compile error

J

Jim Strathmeyer

(if this is OT, please let me know where to post it)

Basically I'm trying to 'g++ -c a.cpp' which includes a.h. a.h includes
some things, including b.h, which includes c.h (each header defining
classes A, B, and C, respectively.) Now, C inherits B, but as you can see
by the string of events above, by the time it gets to 'class C : public B'
B hasn't been defined yet.

I also have the same where the same situation happens and class C
has a member of type B or A.

Is there any elegant solution to this?

Is there a precompile/linking/whatever tutorial anywhere?
 
V

Victor Bazarov

Jim Strathmeyer said:
(if this is OT, please let me know where to post it)

Basically I'm trying to 'g++ -c a.cpp' which includes a.h. a.h includes
some things, including b.h, which includes c.h (each header defining
classes A, B, and C, respectively.) Now, C inherits B, but as you can see
by the string of events above, by the time it gets to 'class C : public B'
B hasn't been defined yet.

Sounds wrong. If C inherits B, why does b.h include c.h? It seems that
the reverse inclusion is in order.
I also have the same where the same situation happens and class C
has a member of type B or A.

If C has a member of type A, then c.h should include a.h. If C has
a member of type B, then c.h should include b.h. Same problem, same
solution.
Is there any elegant solution to this?

How about you read the FAQ first, and then follow the recommendations
put forth in 5.8... You can find FAQ Lite if you visit
http://www.parashift.com/c++-faq-lite/ .
Is there a precompile/linking/whatever tutorial anywhere?

Probably. I don't know of any, though.

V
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top