On Wed 2003-02-12 at 00:06:24 -0800, [EMAIL PROTECTED] wrote:
> Hi,
> I am using the GNU gcc version 3.2 (Mandrake Linux 9.0 3.2-1mdk) to compile 
> the program listed below. I get the compile time error:
> 
> 23: field `cb' has incomplete type
> 
> Can somebody please give me a hint on why the compiler is complaining?

Because you try to use class C before it is defined (you declared it
above, but the definition comes afterwards).

As long as the class is only declared, you may only use it in limited
context. For example, you may create a pointer or reference to the
class, you may also define new types based on the class (typedef).

But when you define class D, the compiler tries determine the memory
layout of the class, and thefore has to know more about C than it does
at that point.

A more detailed explanation can be found in 

  http://www.cuj.com/experts/2002/austern.htm?topic=experts

HTH,

        Benjamin.


[... reduced example to the relevant part ...]
> class C;
> 
> class D
> {
>   C cb;
> };
> 
> class C
> {
>   int foo;
> };
> 
> int main() { }

Attachment: msg119264/pgp00000.pgp
Description: PGP signature

Reply via email to