Operating System - HP-UX
1820882 Members
3415 Online
109628 Solutions
New Discussion

Incomplete type error on compiling a basic C++ program

 
athakur
Occasional Contributor

Incomplete type error on compiling a basic C++ program

While trying to use the forward declaration of a struct within a STL map decl, it gives the foll error

"/opt/aCC/include_std/utility", line 100: error #2070: incomplete type \
is not
allowed
second_type second;


Is this something that has been rectified now ? Unfortunately I am trying to build something where I cannot do w/o the forward declaration, is there any way around it ?

Here is the code that is causing the trouble.

typedef struct cs_cmdmatrix_s cs_cmdmatrix_t;

/* type to define the token name map */
typedef std::map > tokenMap;

struct cs_cmdmatrix_s{

int icmdid;
.
.
.
.

tokenMap subTokens;

};

1 REPLY 1
Dennis Handly
Acclaimed Contributor

Re: Incomplete type error on compiling a basic C++ program

(The correct forum for aCC6 is: HP-UX > languages:
http://forums.itrc.hp.com/service/forums/categoryhome.do?categoryId=150
The moderators have been asked to move it.)

Your source is illegal. You can't use an incomplete type as a container parm.

>is there any way around it?

You could have subTokens be a tokenMap*.
Or have a map.
Or possibly convert cs_cmdmatrix_s to a template?

Note: In C++ it is pretty silly to have typedefs like this:
typedef struct cs_cmdmatrix_s cs_cmdmatrix_t;
A class tag is a type. So just define and use it as: cs_cmdmatrix