I have code like this:
namespace N {
class B {
public:
virtual void doStuff(B *) = 0;
};
}
// not in a namespace
class Derived : public N::B {
public:
void doStuff(B *); // Should this be N::B, or is B ok?
};
Do I need the namespace qualifier where Derived refers to it’s base class? GCC and MSVC are happy with the code as written, but another compiler complains unless I put the namespace in. What does the C++ standard say?
Inside the class definition B is OK. That’s the so-called injected class name.
This also refers to templates (not counting dependent bases). E.g.
In general the base class (and the class itself) can be referred to inside the class definition without qualification or template arguments.
Quotes from the standard:
From this definition it follows that the name of the class itself is publicly accessible from the class, and therefore is available in derived classes. Which proves my point about B being OK along with N::B because the name B is inherited
Btw, this also explains why the following is invalid:
14.6.1 Speaks about injected class names in templates. It is far too long to paste here.
Hth