Is the following code valid with C++ standard? It’s strange that C::B would work because struct B is in A’s namespace. But it does compile fine with gcc.
struct A { struct B {}; };
struct C : public A::B {};
struct D : public C::B {};
If this is standard conforming C++, what are reasonable applications for this construct?
Thanks.
Yes, it’s valid C++. A class in its own scope (so both
BandB::Brefer to the same classB), and a class’s parent class is in its own scope. So sinceBis inC‘s scope andBis in its own scope,C::Brefers toBwhich isA::B.(Side note: do not confuse a namespace with a scope.)
C++03 §9 paragraph 2 says: