Is there a way to predefine nested classes in C ++?

Possible duplicate:
Forward the declaration of nested types / classes in C ++

For simple cross-reference of classes, it is possible to pre-stick class names and use them as a reference. So the view is a pointer. But in case I want to cross-reference the nested class of both (see Example below), I ran into difficulties, because there seems to be no way to pre-set the nested class.

So my question is: is there a way to predefine nested classes so that my example can work?

If not: is there a general workaround for this that doesn't code too ugly?

// Need to predeclare it to use it inside 'First'
class Second;
class Second::Nested; // Wrong

// Definition for my 'First' class
class First
{
public:
    Second::Nested* sested; // I need to use the nested class of the 'Second' class.
                            // Therefore I need to predeclare the nested class.
    class Nested { };
};

// Definition for my 'Second' class
class Second
{
public:
    First::Nested* fested; // I need to use the nested class of the 'First' class.
                           // This is okay.
    class Nested { };
};
+5
source share
1 answer

, - .

...

: .

class Wrapper
{
public:

   // Forward declarations
   class FirstNested;
   class SecondNested;

   // First class
   class First
   {
   public:
      SecondNested* sested;
   };

   // Second class
   class Second
   {
   public:
      FirstNested* fested;
   };
};

Wrapper::A Wrapper::B, , .

+4

All Articles