invalid use of undefined type, .h file confusion

V

vfunc

I have three files tbenbase.h, tbenbase.cpp and tbtst.cpp
The class enmutable is forward declared in tbenbase.h and defined in
tbenbase.cpp.
This is within namespace tb in all files. The header is referenced at
the top
of tbtst.cpp outside of the namespace.

the reference in tbtst.cpp is
class eninv : public enmutable

the class declaration starts
class enmutable : public enbase

and the forward declaration is
class enmutable;

the error is
tbtst.cpp:9: error: invalid use of undefined type `struct
tb::enmutable'

struct?
My compiler is gcc, I do not mention .h to the compiler / linker in the
make file.
How do I correct this?
 
A

Audison.Athena

It seems that you should move the emutable class definition from
thenbase.cpp to thenbase.h file. This error is due to an incomplete
type error.
because the expression "class eninv : public enmutable" in tbtst.cpp
file requires the emutable to be a complete type(it means by so far it
should be able to see the complete type definition of emutable),
however from tbenbase.h file it could only see a forward declaration
about enmutable.
 
V

vfunc

No, I tried this and not suprisingly it tells me that it is redefined
in thenbase.cpp.
I am going in circles because this is the error that prompted me to
split thenbase.cpp
into two files in the first place.
 
V

vfunc

OK, thanks for the help. A case of thinking through what it looks like
to the compiler.
 
A

Audison.Athena

you should enumutable class definition to the thenbase.h file and
remove corresponding definition in thenbase.cpp file, then both in
thenbase.cpp file and tbtst.cpp file include the thenbase.h file, then
no redefinition error will occur.
 
V

vfunc

Well until you entered the thread there was only one person that helped
me, so the ambiguity is in your head.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top