C++ "Missing function header?"

Started by
4 comments, last by Iccarus 18 years ago
I'm unsure what this error is or how to fix it error C2447: '{' : missing function header (old-style formal list?)

MONSTER* MonsterMasterList(int number);
{  // Error occurs here
	MONSTER monsterlist[7];
	monsterlist[0].CreateMonster("Wolf Cub",8,0,1,3,5,0,2,1,0,0,0,0,0,9,false,0);
	monsterlist[1].CreateMonster("Highwayman",10,0,3,2,5,0,2,2,0,0,0,0,0,9,false,0);
	monsterlist[2].CreateMonster("Ochanon",20,5,1,3,9,1,5,8,0,0,0,1,0,9,false,2);
	monsterlist[3].CreateMonster("Earth Spirit",5,20,0,1,20,3,20,20,3,0,0,4,50,3,false,1);				 
	monsterlist[4].CreateMonster("Wild Horse",15,0,3,8,5,0,10,7,0,0,0,0,0,9,false,0);				 
	monsterlist[5].CreateMonster("Bear",20,0,5,8,1,0,3,5,0,0,0,0,0,9,false,0);
	monsterlist[6].CreateMonster("Imperial Soldier",15,0,6,10,5,0,20,10,0,0,0,0,0,9,false,0);

	return(&monsterlist[number]);
}



Thats the source code for it. Any help will be greatly appreciated.
Unless I say otherwise assume I'm talking bout c++. Make things a lot easier :D
Advertisement
Well, for one your code wouldn't work even if it compiled.

You are returning the address of a local variable, and because of scoping the variable will be destroyed on leaving the function.

If you were to make MONSTER monsterlist[7]; into static MONSTER monsterlist[7]; then it might work...

Also, you have a semicolon at the end of the function signature

MONSTER* MonsterMasterList(int number); // < --- here{
If you havent fixed this problem yet:

In the error it has : '{' meaning something is going on with that character.

Your function should, as suggested drop the ';' at the end of the functions declaration line.

And also when the other guys was talking about return &whatever, whatever gets deleted as soon as the function goes out of scope (when your program is done executing the function), so you are giving the address of something that doesnt exist anymore :)

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Try to compile this Iccarus
MONSTER* MonsterMasterList(int number){  // Error occurs hereMONSTER monsterlist[7];monsterlist[0].CreateMonster("Wolf Cub",8,0,1,3,5,0,2,1,0,0,0,0,0,9,false,0);monsterlist[1].CreateMonster("Highwayman",10,0,3,2,5,0,2,2,0,0,0,0,0,9,false,0);monsterlist[2].CreateMonster("Ochanon",20,5,1,3,9,1,5,8,0,0,0,1,0,9,false,2);monsterlist[3].CreateMonster("Earth Spirit",5,20,0,1,20,3,20,20,3,0,0,4,50,3,false,1); monsterlist[4].CreateMonster("Wild Horse",15,0,3,8,5,0,10,7,0,0,0,0,0,9,false,0); monsterlist[5].CreateMonster("Bear",20,0,5,8,1,0,3,5,0,0,0,0,0,9,false,0);monsterlist[6].CreateMonster("Imperial Soldier",15,0,6,10,5,0,20,10,0,0,0,0,0,9,false,0);return(&monsterlist[number]);}
This has been said twice already, but I'm going to repeat it because it's so darn important:

Returning the address of a local variable = Boom!
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
Sorry should have posted. I've fixed the error (and the returning local variable)
Unless I say otherwise assume I'm talking bout c++. Make things a lot easier :D

This topic is closed to new replies.

Advertisement