Forward declaration of nested types/classes in C++

I recently got stuck in a situation like this:

class A
{
public:
    typedef struct/class {…} B;
…
    C::D *someField;
}

class C
{
public:
    typedef struct/class {…} D;
…
    A::B *someField;
}

Usually you can declare a class name:

class A;

But you can’t forward declare a nested type, the following causes compilation error.

class C::D;

Any ideas?

7 Answers
7

Leave a Comment