I’m having a problem when trying to compile these two classes (Army and General) in their own header files:
#ifndef ARMY_H
#define ARMY_H
#include "definitions.h"
#include "UnitBase.h"
#include "UnitList.h"
#include "General.h"
class Army
{
public:
Army(UnitList& list);
~Army(void);
UnitBase& operator[](const ushort offset);
const UnitBase& operator[](const ushort offset) const;
const uint getNumFightUnits() const;
const ushort getNumUnits() const;
const General<Warrior>* getWarrior() const;
private:
UnitBase** itsUnits;
uint itsNumFightUnits;
ushort itsNumUnits;
WarriorGeneral* itsGeneral;
};
#endif
and
#ifndef GENERAL_H
#define GENERAL_H
#include "generalbase.h"
#include "Warrior.h"
class Army;
template <class T>
class General : public GeneralBase, public T
{
public:
General(void);
~General(void);
void setArmy(Army& army);
const Army& getArmy() const;
private:
Army* itsArmy;
};
typedef General<Warrior> WarriorGeneral;
#endif
I have tried forward declaring WarriorGeneral in Army.h, but it doesn’t seem to work, perhaps because it’s a template instance? Anyway, the errors I’m getting with the above version are several of this kind and related problems:
Army.h(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
They’re not even unresolved linker problems… Note I put the typedef of WarriorGeneral in the General.h file. I don’t know whether this is correct. Is there anything that can be done to make this work?
Thanks in advance!
I can’t tell what
Army.hline 21 is because the one you posted doesn’t have that many lines. The only thing I can see that’s not declared in that header isUnitList. Is it properly forward-declared or have a header include you aren’t showing us?Do
generalbase.horWarrior.hincludeArmy.h? If so, that would cause the seemingly circular includes. Try having it not do the include but forward declareArmyinstead.