Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

special case of base class of Inner class

In c++, is it possible to declare inner class (CInner) such that it has outer class (COuter) as its base class ?

This question is about c++ technicalities. Not question of programming style or personal preferences.

like image 806
Andrei Avatar asked Dec 17 '22 13:12

Andrei


1 Answers

Yes. This compiles:

class COuter
{
    class CInner;
};

class COuter::CInner : public COuter
{
};

The reason this is required is that a derived class requires that the entire definition be present for its own definition. So you just need to make sure that the outer class is completely defined before the inner class's definition starts.

like image 123
John Calsbeek Avatar answered Jan 02 '23 14:01

John Calsbeek