Home c++ C++, nested classes with external definition

C++, nested classes with external definition

Author

Date

Category

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.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions