1

I would like to have a class inherit from its enclosed class, as in:

class A : public A::B {
public:
    class B {};
};

However, the compiler complains that A::B is not defined:

error: expected class-name before '{' token
 class A : public A::B {

That is, A::B won't be usable until the definition of A is complete.

I have tried to preface the above with

class A;
class A::B;

But it doesn't help. How can I get this declared and defined correctly?

Note: Essentially, I am trying to do the opposite of this question.

Community
  • 1
  • 1
George Hilliard
  • 15,402
  • 9
  • 58
  • 96

2 Answers2

3

This is not possible, there is no way to declare inner class without defining the outer class.

StenSoft
  • 9,369
  • 25
  • 30
3

At the point where you specify the inheritance, the inner class is not yet know. Thus you can't do that. But if the point is to limit the scope, then just use a namespace, e.g. call it detail or implementation.

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331