I have a situation in which A has a reference to a class C defined inside B, and C has an instance of class B.
When I try to compile the code below, I get "field a has incomplete type
". I assume this is because the compiler does not know how much memory it should allocate for an instance of A.
class A;
class B {
public:
class C {
A a;
};
};
class A {
A(const B::C& _c)
: c(_c)
{}
const B::C& c;
};
But when I try to compile this, I get "C in class B does not name a type
":
class B;
class B::C;
class A {
A(const B::C& _c)
: c(_c)
{}
const B::C& c;
};
class B {
public:
class C {
A a;
};
};
How can I convince the compiler that B::C
is a real type?