[问题] friend function定义在class里

楼主: Lipraxde (Lipraxde)   2019-02-13 14:55:05
编译器(Ex: GCC, clang, VC++...)+目标环境(跟开发平台不同的话需列出)
clang、gcc
问题(Question):
有 class A、class B、function foo
B 是 A 的 friend
foo 是 B 的 friend
把 foo 的定义写在 class B 里面
用 clang 编译可以在 foo 里面存取 A 的私有成员,gcc 则不行
B 的 member function bar 可以存取 A 的私有成员,是因为 bar 属于 B
B 的 friend function 不属于 B,不过定义写在 B 里面,那是属于 B 还是不属于 B?
程式码(Code):(请善用置底文网页, 记得排版,禁止使用图档)
https://gcc.godbolt.org/z/9aNGEX
作者: uranusjr (←這人是超級笨蛋)   2019-02-13 15:25:00
定义在 B 里只会让 foo inline, 不会让 foo 属于 B感觉是 Clang 的 bug...?
作者: notBeing (read and be read)   2019-02-13 15:26:00
不属于

Links booklink

Contact Us: admin [ a t ] ucptt.com