I want to make an embedded class with the definition outside the body of the comprehensive class.
For example, so:
class enclose :: inner
{
// ...
};
Class Enclose
{
Private:
Class Inner;
INNER INNER;
};
Compiler tells me that inner inner
leads to an attempt to create an incomplete type object.
Tell me how can this be done? And is it possible at all?
Answer 1, Authority 100%
No, it is impossible to do this. It is if you immediately in the covering class want to announce the field of the attached class, then the invested class will have to be determined directly in the covering class.
You can somehow erupted like
class dummybase
{
Protected:
Class Inner;
};
Class Dummybase :: Inner
{
};
Class Enclose: dummybase
{
Inner a;
};
But is it worth it – you decide. This option for defining nested classes (if there are many) gives you a decrease in toasting the external namespace, but nothing else is actually nothing. Neither access to the members of enclose
, nor the corresponding search for names from Inner
in Enclose
you do not get this way.
Answer 2, Authority 50%
Create an object, an even indefinite class you cannot, just as you can not store your copy in the class. However, if you still want to define a class later, you can: store Refer to
or pointer.
You can simply hide the inner
class in the namespace, and, if necessary, make it another of your class.