这是关于问题
A class name introduced inside a class is not treated as a nested class name
我很困惑为什么Part1和Part2与标准的§3.3.2[basic.scope.pdecl] / p7不同:
两者都是Elaborated Type说明符,应该属于同一部分但似乎范围似乎不同
struct A
{
struct B;
B* m_b;
};
struct A
{
struct B* m_b;
};
请指导我。
答案 0 :(得分:2)
也许这个小例子将有助于详细说明:
#include <iostream>
struct B {
void call() { std::cout << "B" << std::endl; }
};
struct A {
struct B* p;
};
struct A2 {
struct B;
struct B* p;
};
struct A2::B {
void call() { std::cout << "A2::B" << std::endl; }
};
int main()
{
B pb;
A2::B pb2;
auto a = A { &pb };
a.p->call();
auto a2 = A2 { &pb2 };
a2.p->call();
return 0;
}
预期结果:
B
A2::B
要点:
A :: p是B *
A2 :: p是A2 :: B *
A2 :: B和B是完全不同的类