Jump to content
  • Advertisement
Sign in to follow this  
Iccarus

C++ "Missing function header?"

This topic is 4516 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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
{

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
Try to compile this Iccarus

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]);
}

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!