### Local Function Definition error

I've scoured the Web and my code for a solution to this error, but I can't find one! Please help.
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316`` ``````#ifndef FUNCTION_H #define FUNCTION_H #include #include #include #include #include #include //... int function(int a, char b, int c, std::string d, std::string e, std::string f, class1& hero, class2& dog, class3& heroine, class4& object4, /*etc, all the way up to 12 each*/ std::string eles[])//all classes and relating variables are already defined. {//error is on this line int choice2 = 0; if((d == object4.name)&&(e == object5.name)&&(f == object6.name)) { while((object4.hpStat > 0)||(object5.hpStat > 0)||(object6.hpStat > 0)){ c = 0; if((dog.currenthpStat <= 0)&&(hero.currenthpStat <= 0)&&(heroine.currenthpStat <= 0)){ object4.hpStat = 0; object5.hpStat = 0; object6.hpStat = 0; } //Dog's turn if(dog.currenthpStat > 0) { std::cout << "What will Dog do?\n"; std::cout << "[A]ttack\n"; std::cin >> b; system("CLS"); std::cout << "Lvl[1]Attack\n"; std::cout << "[S]kills\n"; std::cout << "[E]lements\n"; b = toupper(b); if(b == '1') { c = ((2 * dog.level + 2)*dog.powerStat + 40)/object4.armorStat; system("CLS"); } if(b == 'S') { std::cout << "[C]homp\n"; if(dog.level >= 3) { std::cout << "[W]arbark\n"; } if(dog.level >= 5) { std::cout << "[R]abid Dog\n"; } std::cin >> b; b = toupper(b); if(b == 'C') { c = ((2 * dog.level + 2)*dog.powerStat + 50)/object4.armorStat; c = c * 1.5; system("CLS"); } if(b == 'W') { dog.powerStat = dog.powerStat * 1.25; hero.powerStat = hero.powerStat * 1.25; heroine.powerStat = heroine.powerStat * 1.25; c = 0; system("CLS"); } if(b == 'R') { c = ((2 * dog.level + 2)*dog.powerStat + 105)/object4.armorStat; c = c * 1.5; } } if(b == 'E') { for(int i = 0; i < 10; i++) { if(eles[i] == "LIGHT BALL") { std::cout << "[1] Light Ball\n"; } if(eles[i] == "AQUA SPRAY") { std::cout << "[2] Aqua Spray\n"; } if(eles[i] == "FLAME SHOT") { std::cout << "[3] Flame Shot\n"; } if(eles[i] == "PEBBLE SPRAY") { std::cout << "[4] Pebble Spray\n"; } if(eles[i] == "DARK BALL") { std::cout << "[5] Dark Ball\n"; } if(eles[i] == "GALE") { std::cout << "[6] Gale\n"; } if(eles[i] == "LIGHT RAY") { std::cout << "[7] Light Ray\n"; } if(eles[i] == "JET SPRAY") { std::cout << "[8] Jet Spray\n"; } if(eles[i] == "FIRE SPRAY") { std::cout << "[9] Fire Spray\n"; } if(eles[i] == "SLINGSHOT") { std::cout << "[10] Slingshot\n"; } if(eles[i] == "DARKNESS RAY") { std::cout << "[11] Darkness Ray\n"; } if(eles[i] == "AIR BLAST") { std::cout << "[12] Air Blast\n"; } if(eles[i] == "LIGHT BEAM") { std::cout << "[13] Light Beam\n"; } if(eles[i] == "FIREBALL") { std::cout << "[14] Fireball\n"; } if(eles[i] == "AQUA BALL") { std::cout << "[15] Aqua Ball\n"; } if(eles[i] == "BOULDER") { std::cout << "[16] Boulder\n"; } if(eles[i] == "FALL SO HARD") { std::cout << "[17] Fall So Hard\n"; } if(eles[i] == "ANTICYCLONE") { std::cout << "[18] Anticyclone\n"; } if(eles[i] == "PHOTON BLAST") { std::cout << "[19] Photon Blast\n"; } if(eles[i] == "FIREBOMB") { std::cout << "[20] Firebomb\n"; } if(eles[i] == "WATER BOMB") { std::cout << "[21] Water Bomb\n"; } if(eles[i] == "LANDSLIDE") { std::cout << "[22] Landslide\n"; } if(eles[i] == "DARKNESS BEAM") { std::cout << "[23] Darkness Beam\n"; } if(eles[i] == "CYCLONE") { std::cout << "[24] Cyclone\n"; } if(eles[i] == "LASER BEAM") { std::cout << "[25] Laser Beam\n"; } if(eles[i] == "ERUPTION") { std::cout << "[26] Eruption\n"; } if(eles[i] == "FLOOD") { std::cout << "[27] Flood\n"; } if(eles[i] == "EARTHQUAKE") { std::cout << "[28] Earthquake\n"; } if(eles[i] == "EVENT HORIZON") { std::cout << "[29] Event Horizon\n"; } if(eles[i] == "THUNDERSTORM") { std::cout << "[30] Thunderstorm\n"; } if(eles[i] == "STAR DEATH") { std::cout << "[31] Star Death\n"; } if(eles[i] == "SUPERNOVA") { std::cout << "[32] Supernova\n"; } if(eles[i] == "TSUNAMI") { std::cout << "[33] Tsunami\n"; } if(eles[i] == "FAULT") { std::cout << "[34] Fault\n"; } if(eles[i] == "BLACKHOLE") { std::cout << "[35] Blackhole\n"; } if(eles[i] == "TORNADO") { std::cout << "[36] Tornado\n"; } } std::cin >> choice2; if(choice2 == 4) { c = ((2 * dog.level + 2)*dog.magicStat + 35)/object4.magicArmorStat; c = c * 1.5; system("CLS"); } if((choice2 <= 3)||((choice2 >= 5)&&(choice2 <= 6))) { c = ((2 * dog.level + 2)*dog.magicStat + 35)/object4.magicArmorStat; system("CLS"); } if(choice2 == 10) { c = ((2 * dog.level + 2)*dog.magicStat + 50)/object4.magicArmorStat; c = c * 1.5; system("CLS"); } if(((choice2 >= 7)&&(choice2 <= 9))||((choice2 >= 11)&&(choice2 <= 12))) { c = ((2 * dog.level + 2)*dog.magicStat + 50)/object4.magicArmorStat; system("CLS"); } if(choice2 == 16) { c = ((2 * dog.level + 2)*dog.magicStat + 65)/object4.magicArmorStat; c = c * 1.5; system("CLS"); } if(((choice2 >= 13)&&(choice2 <= 15))||((choice2 >= 17)&&(choice2 <= 18))) { c = ((2 * dog.level + 2)*dog.magicStat + 65)/object4.magicArmorStat; system("CLS"); } if(choice2 == 22) { c = ((2 * dog.level + 2)*dog.magicStat + 80)/object4.magicArmorStat; c = c * 1.5; system("CLS"); } if(((choice2 >= 19)&&(choice2 <= 22))||((choice2 >= 23)&&(choice2 <= 24))) { c = ((2 * dog.level + 2)*dog.magicStat + 80)/object4.magicArmorStat; system("CLS"); } if(choice2 == 28) { c = ((2 * dog.level + 2)*dog.magicStat + 95)/object4.magicArmorStat; c = c * 1.5; system("CLS"); } if(((choice2 >= 25)&&(choice2 <= 27))||((choice2 >= 29)&&(choice2 <= 30))) { c = ((2 * dog.level + 2)*dog.magicStat + 95)/object4.magicArmorStat; system("CLS"); } if(choice2 == 34) { c = ((2 * dog.level + 2)*dog.magicStat + 120)/object4.magicArmorStat; c = c * 1.5; system("CLS"); } if(((choice2 >= 31)&&(choice2 <= 33))||((choice2 <= 36)&&(choice2 >= 35))) { c = ((2 * dog.level + 2)*dog.magicStat + 120)/object4.magicArmorStat; system("CLS"); } } if(c > 0) { std::cout << "Who will you target?\n"; std::cout << "[1] Enemy #1\n"; std::cout << "[2] Enemy #2\n"; std::cout << "[3] Enemy #3\n"; std::cin >> choice2; std::cout << "\n\n\n\n\n\t\t@\t\t@"; std::cout << "\n\n\n\n\n\t\t@\t\t@"; std::cout << "\n\n\n\n\n\t\t@\t\t@"; Sleep(500); if(choice2 == 1) { std::cout << "ENEMY took " << c << " HP c!\n"; object4.hpStat -= c; } if(choice2 == 2) { std::cout << "ENEMY took " << c << " HP c!\n"; object5.hpStat -= c; } if(choice2 == 3) { std::cout << "ENEMY took " << c << " HP c!\n"; object6.hpStat -= c; } Sleep(1000); } }``````

That was just part of the code, most of which I'm afraid might be unnecessary, since the error is as follows:
gameidea\program.h(44) : error C2601: 'function' : local function definitions are illegal
Can anyone figure it out?
And which line in header line 44 relates to? because it looks like you omitted some parts
EDIT: looks like you forgot to close brace on some of previous lines
Last edited on
It means that 'function' is inside another function. This probably means that you forgot a brace } somewhere before 'function' definition (maybe in one of the files you included - the error might be there)

See http://msdn.microsoft.com/en-us/library/sba3hty9(v=vs.71).aspx
consider using a switch statement here:
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144`` ``````if(eles[i] == "LIGHT BALL") { std::cout << "[1] Light Ball\n"; } if(eles[i] == "AQUA SPRAY") { std::cout << "[2] Aqua Spray\n"; } if(eles[i] == "FLAME SHOT") { std::cout << "[3] Flame Shot\n"; } if(eles[i] == "PEBBLE SPRAY") { std::cout << "[4] Pebble Spray\n"; } if(eles[i] == "DARK BALL") { std::cout << "[5] Dark Ball\n"; } if(eles[i] == "GALE") { std::cout << "[6] Gale\n"; } if(eles[i] == "LIGHT RAY") { std::cout << "[7] Light Ray\n"; } if(eles[i] == "JET SPRAY") { std::cout << "[8] Jet Spray\n"; } if(eles[i] == "FIRE SPRAY") { std::cout << "[9] Fire Spray\n"; } if(eles[i] == "SLINGSHOT") { std::cout << "[10] Slingshot\n"; } if(eles[i] == "DARKNESS RAY") { std::cout << "[11] Darkness Ray\n"; } if(eles[i] == "AIR BLAST") { std::cout << "[12] Air Blast\n"; } if(eles[i] == "LIGHT BEAM") { std::cout << "[13] Light Beam\n"; } if(eles[i] == "FIREBALL") { std::cout << "[14] Fireball\n"; } if(eles[i] == "AQUA BALL") { std::cout << "[15] Aqua Ball\n"; } if(eles[i] == "BOULDER") { std::cout << "[16] Boulder\n"; } if(eles[i] == "FALL SO HARD") { std::cout << "[17] Fall So Hard\n"; } if(eles[i] == "ANTICYCLONE") { std::cout << "[18] Anticyclone\n"; } if(eles[i] == "PHOTON BLAST") { std::cout << "[19] Photon Blast\n"; } if(eles[i] == "FIREBOMB") { std::cout << "[20] Firebomb\n"; } if(eles[i] == "WATER BOMB") { std::cout << "[21] Water Bomb\n"; } if(eles[i] == "LANDSLIDE") { std::cout << "[22] Landslide\n"; } if(eles[i] == "DARKNESS BEAM") { std::cout << "[23] Darkness Beam\n"; } if(eles[i] == "CYCLONE") { std::cout << "[24] Cyclone\n"; } if(eles[i] == "LASER BEAM") { std::cout << "[25] Laser Beam\n"; } if(eles[i] == "ERUPTION") { std::cout << "[26] Eruption\n"; } if(eles[i] == "FLOOD") { std::cout << "[27] Flood\n"; } if(eles[i] == "EARTHQUAKE") { std::cout << "[28] Earthquake\n"; } if(eles[i] == "EVENT HORIZON") { std::cout << "[29] Event Horizon\n"; } if(eles[i] == "THUNDERSTORM") { std::cout << "[30] Thunderstorm\n"; } if(eles[i] == "STAR DEATH") { std::cout << "[31] Star Death\n"; } if(eles[i] == "SUPERNOVA") { std::cout << "[32] Supernova\n"; } if(eles[i] == "TSUNAMI") { std::cout << "[33] Tsunami\n"; } if(eles[i] == "FAULT") { std::cout << "[34] Fault\n"; } if(eles[i] == "BLACKHOLE") { std::cout << "[35] Blackhole\n"; } if(eles[i] == "TORNADO") { std::cout << "[36] Tornado\n"; }``````
closed account (3qX21hU5)
Also you are using function as a function name which is highly highly discouraged. I would recommend you rename it to something else.
Thanks for the help! The problem WAS a forgotten '}' bracket (it was in a different header file). Thank you!

@Zereo: I did not REALLY use 'function' as the name of a function; I just did that for purposes of the post.
Topic archived. No new replies allowed.