I'm doing work and I think the trouble I'm having is with circular includes.
I have Unit as a base class, and Hero and Army both derive from Unit.
Hero needs to have a vector of Army*'s, and Army needs to have a single Hero*. Here is how the code is setup:
andCode:#ifndef ARMY_H #define ARMY_H #include "Unit.h" #include "Hero.h" using namespace std; class Army : public Unit { public: Hero* getHero(){return phero;} void setHero(Hero *theHero){phero = theHero;} private: Hero *phero; // ... etc
But when it's trying to compile Hero, it sees that Army is included, so it tries to compile that, which says that Hero is included, etc. So I believe I've reached a circular include.Code:#ifndef HERO_H #define HERO_H #include<iostream> #include "Army.h" #include <string> #include<vector> using namespace std; class Hero : public Unit { public: void addArmy(Army*); void removeArmy(Army*); private: vector<Army*> army; // ... etc
Is there any way to achieve this functionality without doing a restructure of my classes? Thanks for help.



LinkBack URL
About LinkBacks


