472,794 Members | 3,648 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,794 software developers and data experts.

What is "incomplete type?" (compiler error)

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
5 33047

"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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mat DeLong | last post by:
Can someone explain this error to me? : main.cpp:9: instantiated from `void show(const LIST::List<T>&) ' main.cpp:23: instantiated from here list.cpp:58: error: dependent-name...
5
by: kj | last post by:
Hi. I'm trying to compile some software from source, and I'm getting an error I can't figure out. The error in question is key_events.h:38: field `id' has incomplete type and the lines...
2
by: Lenonardo | last post by:
Hi. I'm writing a VB.Net application to update multiple Excel Worksheets. I'm using late binding (i.e. all variables are objects + use createobject) I develop the application on an XP...
3
by: Ed L. | last post by:
On 7.4.6, is there any problem with defining one column of a view to be a string literal? For example ... $ psql -c "create view fooview as select 'bar' as footype" WARNING: column "footype"...
6
by: geoffrobinson | last post by:
Hi, I'm serializing an object using XmlSerializer. It is serializing, but we are getting errors upon deserialization. We use the following code to serialize: FileStream fs = new...
3
by: John Sasso | last post by:
In my Yacc .y file I defined: %union { int value; struct Symbol Sym; } The Symbol struct I defined in a header file I #included in the Prologue section of the .y file as:
3
by: IR | last post by:
Hi, I've been trying to do the following (which doesn't compile) : template<class T, class F = Example<T struct Example { F foo(); };
5
by: Charles Packer | last post by:
In the code example below, why does the reference to gdk_pixbuf_new_from_file in main compile okay, but in subr2 gives the error "dereferencing pointer to incomplete type"? A search through this...
5
by: tejesh | last post by:
I am trying to compile the following code int backend_sm_run(struct interface_data *ctx) { xsup_assert((ctx != NULL), "ctx != NULL", TRUE); xsup_assert((ctx->statemachine != NULL),...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.