Local Function Definition error
Apr 22, 2013 at 3:14pm UTC
I've scoured the Web and my code for a solution to this error, but I can't find one! Please help.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
#ifndef FUNCTION_H
#define FUNCTION_H
#include<iostream>
#include<string>
#include<cstdlib>
#include<time.h>
#include<ctime>
#include<windows.h>
//...
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?
Apr 22, 2013 at 3:22pm UTC
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 Apr 22, 2013 at 3:23pm UTC
Apr 22, 2013 at 3:30pm UTC
Apr 22, 2013 at 3:37pm UTC
consider using a switch statement here:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
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" ;
}
Apr 22, 2013 at 3:38pm UTC
Also you are using function as a function name which is highly highly discouraged. I would recommend you rename it to something else.
Apr 23, 2013 at 2:56pm UTC
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.