Archived

This topic is now archived and is closed to further replies.

Nazrix

Header problems

Recommended Posts

I'm having a problem with including headers:
    
// Npc.h


#include "mission.h"


class Npc : public Person
{

Mission *currMission;

  

  
      
// Mission.h


#include "npc.h"

class Mission
{
   public:
	
   Npc *told,  //npc that told the npc to do the mission

       *involved; //npc doing the mission


	
    
So, basically each header needs the other and that seems to be giving me problems. If Npc.h includes mission.h, mission.h doesn't know what the class Npc is.
A CRPG in development... Need help? Well, go FAQ yourself. [edited by - Nazrix on December 23, 2002 4:39:40 PM]

Share this post


Link to post
Share on other sites
The errors are:


Compiling...
main.cpp
c:\documents and settings\shizzle nizzle\my documents\vcprojects\backed up ai\mission.h(13) : error C2143: syntax error : missing ';' before '*'
c:\documents and settings\shizzle nizzle\my documents\vcprojects\backed up ai\mission.h(13) : error C2501: 'Npc' : missing storage-class or type specifiers
c:\documents and settings\shizzle nizzle\my documents\vcprojects\backed up ai\mission.h(13) : error C2501: 'told' : missing storage-class or type specifiers
c:\documents and settings\shizzle nizzle\my documents\vcprojects\backed up ai\mission.h(14) : error C2501: 'involved' : missing storage-class or type specifiers


[edited by - Nazrix on December 23, 2002 4:41:41 PM]

Share this post


Link to post
Share on other sites
You have circular include problems.

Use forward declarations. I''m not sure how you choose which one goes where though, hopefully someone will clarify.

E.g. in mission.h you can put:

class Npc;

before everything and not include the "npc.h" file explicitly.

Oh and watch the public members

Share this post


Link to post
Share on other sites