Compile error in c++ while doing something new

Associate
Joined
6 Sep 2007
Posts
2
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

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
conq\ARMY.h(61) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
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.

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.
 
There isn't a BOOL data type as standard is there? Do you need to include stdlib or something? Not done C++ in a while...
 
bool (note the case) is standard C++
OP: "So, the GAME class contains an ARMY class." < you mean the game class has an instance of army as a member?
More code (i.e. stripped down but should be compilable) would help.
 
Try removing the const from the function definition temporarily. The compiler thinks that you haven't supplied the type of something that you should have. bool should be safe enough, so I think it is the type of the function argument that it is complaining about.

And yes, a little more code wouldn't go amiss :D
 
Last edited:
Back
Top Bottom