Reputation: 105
This is regarding the question
A class name introduced inside a class is not treated as a nested class name.
I am confused why Part1 and Part2 are different with respect to §3.3.2 [basic.scope.pdecl]/p7 of the standard:
Both are Elaborated Type specifiers and should fall into same section But it seems that there scope seems to be different
struct A
{
struct B;
B* m_b;
};
struct A
{
struct B* m_b;
};
Please guide me in this.
Upvotes: 0
Views: 215
Reputation: 69884
Maybe this little example will help to elaborate:
#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;
}
expected results:
B
A2::B
Summary:
A::p is a B*
A2::p is a A2::B*
A2::B and B are entirely different classes
Upvotes: 2