struct A ; // A is an incomplete type (known in name, but not known in size)
// A is a class that has been declared but not defined
extern A object ; // fine; we can declare an object of an incomplete type
// A object ; // ****error: A is an incomplete type, can't define an object
// int sz = sizeof(A) ; // ****error: A is an incomplete type, size is not known
A* pointer = &object ; // fine, size and layout of pointer is known
A& reference = object ; // fine, we can create an alias for an object of an incomplete type.
extern A array[20] ; // fine; declaration of an object of incomplete type
// int sz_array = sizeof(array) ; // ****error: A[20] is of an incomplete type, size is not known
struct B
{
B( A& a ) : member3(a) {} // fine
// A member ; // ****error: A is an incomplete type, size and layout are not known
A* member2 = nullptr ; // fine
A& member3 ; // fine
};
struct A // start definition of A
{
// A is still an incomplete type at this point
void foo( int v = sizeof(A) ) ; // fine, sizeof(A) need not be known at this point
// char cstr[ sizeof(A) ] ; // ***error: sizeof A is not known
// A member ; // ****error: A is an incomplete type, size and layout are not known
A* member2 = this ; // fine
A& member3 = *this ; // fine
}; // end definition of A
// at this point, A has become a complete type
int sz_array = sizeof(array) ; // fine
A array[20] ; // fine
A object ; // fine;
int sz = sizeof(A) ; // fine
If it was possible just imagine how big a Node object would be. Node contains two nodes that contains two nodes each that also contains two nodes each and so on. The Node object would have to be infinite large. Todays computers have finite amount of memory so that's not going to work. That's why you are forced to use pointers of some kind instead.
But when I have declared a pointer like the following as a member variable, and I don't use a function to allocate it.
Wouldn't it give me the same problem, but now that it is declaring pointers ongoingly?