interlocking class definitions?

S

Stainless

I want a class NPC which has a member variable wpn which is a pointer
to a Weapon class.

However the Weapon class has methods that require pointers to NPC
classes.

so obviously in Weapon.h I include NPC.h
and in NPC.h I include Weapon.h

both have proper #ifndef <blah> #define <blah> #endif structures


but the compiler can't handle it


Is this a valid c++ situation?

Or do I have to use void * and do something like dynamic_cast



--
 
G

Gavin Deane

Stainless said:
I want a class NPC which has a member variable wpn which is a pointer
to a Weapon class.

However the Weapon class has methods that require pointers to NPC
classes.

so obviously in Weapon.h I include NPC.h
and in NPC.h I include Weapon.h

both have proper #ifndef <blah> #define <blah> #endif structures


but the compiler can't handle it


Is this a valid c++ situation?

Or do I have to use void * and do something like dynamic_cast

This is in the FAQ
http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.11

Gavin Deane
 

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,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top