“Inherit” is the wrong word to use, because it has a very specific definition in C ++ that you don’t mean, but yes, you can do it. It is legal:
class A {
protected:
class Nested { };
};
class B : public A {
private:
Nested n;
};
And code that is not in or something that comes from A cannot access or instantiate A :: Nested.
source
share