423,822 Members | 1,356 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,822 IT Pros & Developers. It's quick & easy.

What is "incomplete type?" (compiler error)

P: n/a
g++ compiler 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.
Jul 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"Lou Pecora" <pe**********@THISanvil.nrl.navy.mil> wrote in message
news:pe********************************@ra.nrl.nav y.mil...
g++ compiler 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.


An incomplete type error occurs when you try to use a class (or struct) that
has not yet been fully defined, inside another class. Without seeing your
class definitions for B and C, it's impossible to tell what you're missing,
exactly. But...perhaps you're trying to pass the B object by value to the C
constructor, instead of by const reference as it more often done?

-Howard

Jul 23 '05 #2

P: n/a
In article <rc********************@bgtnsc04-news.ops.worldnet.att.net>,
"Howard" <al*****@hotmail.com> wrote:
"Lou Pecora" <pe**********@THISanvil.nrl.navy.mil> wrote in message
news:pe********************************@ra.nrl.nav y.mil...
g++ compiler 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.


An incomplete type error occurs when you try to use a class (or struct) that
has not yet been fully defined, inside another class. Without seeing your
class definitions for B and C, it's impossible to tell what you're missing,
exactly. But...perhaps you're trying to pass the B object by value to the C
constructor, instead of by const reference as it more often done?

-Howard


Thanks, Howard, for the reply.

I understand what you are saying. I pass B as a reference to A. That
is the C constructor is,

C::C(A &Ainst) { ... }

I have done this with this C class before, but I have written a new B
class inheriting from the same A I used before. But the compiler chokes
right where I try to declare a variable of type C with a B instance
passed to it in the declaration, i.e. C Cinst(Binst), and I am looking
for any clue why. I can see none, but there must be something undefined
for the compiler. I will go back and look, again. Thanks.

-- Lou Pecora (my views are my own) REMOVE THIS to email me.
Jul 23 '05 #3

P: n/a
Well, Duh (dope-slap upside my head), I found the answer to "incomplete
type." It is basically what others have said: some code is undefined.
I thought the header for my container code was included in another
header, but it wasn't only the declaration

class C;

was in that header. So including the container header got rid of the
"incomplete type?" error.

Mea culpa. And thanks to all who answered.

-- Lou Pecora (my views are my own) REMOVE THIS to email me.
Jul 23 '05 #4

P: n/a
Lou Pecora wrote:

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.


This means that C has been declared but not defined.
Here is a simpler example that gives the same error:

class C;

int main()
{
C c(1);
}

If you think C has been defined, then perhaps you have a
problem with #include dependencies.

Jul 23 '05 #5

P: n/a
In article <11*********************@g43g2000cwa.googlegroups. com>,
"Old Wolf" <ol*****@inspire.net.nz> wrote:
Lou Pecora wrote:

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.


This means that C has been declared but not defined.
Here is a simpler example that gives the same error:

class C;

int main()
{
C c(1);
}

If you think C has been defined, then perhaps you have a
problem with #include dependencies.


Thanks. I finally realized I goofed and did not include the C header.
I thought it was included in another header, but only

class C;

was declared. Mea Cupla!

-- Lou Pecora (my views are my own) REMOVE THIS to email me.
Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.