sunny wrote:
why does forward declaration does not work in following code.
struct A;
struct B
{
struct A a;
Because the compiler NEEDS TO KNOW the internals of 'A' here.
>
// struct A *a // WORKS SINCE ITS POINTER
All pointers to objects are of the same size. The compiler does
NOT need to know the internals of 'A' here.
};
struct A
{
struct B b;
};
gives compiler error for incomplete type A. why does forward
declaration of Struct A solve this problem.
The last statement is false. A forward declaration of 'A' does
NOT solve the problem of mutual containment. Nothing can. If
each object 'B' contains a member of type 'A', and, in turn, each
object 'A' contains a member of type 'B', what's the size of the
objects?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask