I am writing a small c++ - program containing a similar structure to the following:
class A {
B * someObjects;
};
typedef A* APointer;
struct B{
APointer a;
int n;
}
Trying to compile this gives a "identifier is undefined" error since struct B is not known inside class A. Otherwise declaring struct B before class A should still give a similar error, since then B does not know APointer, or APointer does not know A. Is there any possibility to make class A and struct B being good friends? Thanks in advance!
You need to forward declare
Bas the compiler has no idea whatBis when it is used inA.Bis considered an incomplete type inAand you are allowed to have a pointer or reference toBinA. You can change your code to: