Hi, I'm playing with passing a reference to a class into one of the class' sub classes, and things are looking dire. Could someone please let me know where I'm going wrong before I lose what's left of my hair!
So, the GAME class contains an ARMY class. One of ARMY's member functions needs access to a few bits and bobs in GAME, so I've got:
Inside GAME.cpp
(the myArmy->move() bit worked before when I didn't try to pass anything in, so there's no problem with pointer initialisation elsewhere for the army)
Inside ARMY.h
Inside ARMY.cpp
Compiling gives a number of lovely errors, the first being
Could someone give me a little guidance please? As usual, no need to do my work for me, but a push in the right direction would be appreciated.
Thanks.
So, the GAME class contains an ARMY class. One of ARMY's member functions needs access to a few bits and bobs in GAME, so I've got:
Inside GAME.cpp
Code:
if (myArmy->move(*this)){ some stuff }
(the myArmy->move() bit worked before when I didn't try to pass anything in, so there's no problem with pointer initialisation elsewhere for the army)
Inside ARMY.h
Code:
bool move(const GAME& game);
Inside ARMY.cpp
Code:
bool ARMY::move(const GAME& game)
{
// if it's got somewhere new move to
if (hasDest){
// move in the correct direction
bool mapUpdateNeeded=0;
// right
if (destX > mapX &&
game.getLandType(mapX+1, mapY) !=0 &&
game.getLandType(maxX+1, mapY) !=3){
mapX++;
mapUpdateNeeded = 1;
} // etc etc for other directions
}
Compiling gives a number of lovely errors, the first being
which is pointing towards the code provided above from ARMY.h. ARMY.h contains a #include for GAME.h, which leaves me totally and embarrassingly stuck.conq\ARMY.h(61) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Could someone give me a little guidance please? As usual, no need to do my work for me, but a push in the right direction would be appreciated.
Thanks.