What is "incomplete type?" (compiler error)

  • Follow


g++ error question.

I have a container C whose constructor takes a class B that is inherited
from an abstract class A.  So I have the line of code:

   B  binstance;
   C  cinstance(binstance);


The compiler gives the error,

   error: variable `C cinstance' has initializer but incomplete type

I am trying to figure out what this means.  What's an incomplete type?
I have all the methods that were abstract in A explicitly in B.  I have
done this before with other classes inherited from the same abstract
class A and had no problems.  Never seen this error before.  What the
heck is going on?  Any information will be greatly appreciated.  I am
stuck.  Thanks.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Reply Lou 5/20/2005 10:18:05 AM

Lou Pecora wrote:
> g++ error question.
> 
> I have a container C whose constructor takes a class B that is inherited
> from an abstract class A.  So I have the line of code:
> 
>    B  binstance;
>    C  cinstance(binstance);
> 
> 
> The compiler gives the error,
> 
>    error: variable `C cinstance' has initializer but incomplete type
> 
> I am trying to figure out what this means.  What's an incomplete type?
> I have all the methods that were abstract in A explicitly in B.  I have
> done this before with other classes inherited from the same abstract
> class A and had no problems.  Never seen this error before.  What the
> heck is going on?  Any information will be greatly appreciated.  I am
> stuck.  Thanks.

The error message clearly specifies that the problems is about class C,
not about class B. The compiler has encountered a declaration of C (like
"class C;") but hasn't seen the whole definition yet. The declaration
makes C a "type" but, without the definition, such type is "incomplete"
and cannot be instantiated.

Did you miss to include the header file that defines class C?

Alberto

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Reply Alberto 5/20/2005 4:00:35 PM


1 Replies
881 Views

(page loaded in 0.014 seconds)

Similiar Articles:













7/24/2012 4:20:52 PM


Reply: