Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im getting an error in my code saying, pokemon2.cpp:43:12: warning: generalized initializer lists are a C++11 extension [-Wc++11-extensions] return {movename, 0, damagevalue, 0, 0, 0,

Im getting an error in my code saying,

pokemon2.cpp:43:12: warning: generalized initializer lists are a C++11 extension

[-Wc++11-extensions] return {movename, 0, damagevalue, 0, 0, 0, 0};

and also

"pokemon2.cpp:48:23: error: expected ';' after return statement return new Pokedex {NULL, NULL};"

here's my code. Not sure why. Can someone fix? (using GCC on Mac)

#include

#include

using namespace std;

struct Move

{

string name;

int selfHPEffect;

int otherHPEffect;

int selfAtkEffect;

int otherAtkEffect;

int selfDefEffect;

int otherDefEffect;

};

struct Pokemon

{

string name;

string type;

int centimeterHeight;

int gramWeight;

int hp;

int attack;

int defense;

Move move1;

Move move2;

};

struct Pokedex

{

Pokemon* p;

Pokedex* rest;

};

Move simpleAttack(string movename, int damagevalue)

{

return {movename, 0, damagevalue, 0, 0, 0, 0};

}

Pokedex* empty()

{

return new Pokedex {NULL, NULL};

}

bool isEmpty(Pokedex* pokedex)

{

if(pokedex != NULL)

{

return true;

}

else

{

return false;

}

}

int length(Pokedex* pokedex)

{

Pokedex* current = pokedex;

int count = 0;

while(current->rest != NULL)

{

current = current->rest;

count ++;

}

return count;

}

Pokedex* prepend(Pokemon* value, Pokedex* rest)

{

Pokedex* newPokedex = new Pokedex;

newPokedex->p = value;

newPokedex->rest = rest;

return newPokedex;

}

string shortDescription(Pokemon* input)

{

string output = (input->name + " (" + input->type + ") ");

return output;

}

string index(Pokedex* input)

{

string output = "";

Pokedex* current = input;

while(current->rest != NULL)

{

Pokemon* name = input->p;

output = output + shortDescription(name);

current = current->rest;

}

return output;

}

int main()

{

int SIZE = 5;

Move none = {"None" , 0, 0, 0, 0, 0, 0};

Move harden = {"Harden" , 0, 0, 0, 0, 6, 0};

Move growth = {"Growth" , 0, 0, 1, 0, 0, 0};

Move supersonic = {"Supersonic" ,-50, 0, 0, 0, 0,-1};

Move poison_sting = {"Poison Sting" ,-15, 0, 0, 0, 0,-1};

Move vine_whip = simpleAttack("Vine Whip", -35);

Move rock_throw = simpleAttack("Rock Throw", -50);

Move slam = simpleAttack("Slam", -80);

Move tackle = simpleAttack("Tackle", -40);

Pokemon metapod =

{

"Metapod",

"Bug",

71,

9900,

50,

20,

55,

harden,

none,

};

Pokemon bellsprout =

{

"Bellsprout",

"Grass, Poison",

71,

4000,

50,

75,

35,

vine_whip,

growth,

};

Pokemon sudowoodo =

{

"Sudowoodo",

"Rock",

119,

38000,

70,

100,

115,

rock_throw,

slam,

};

Pokemon magnemite =

{

"Magnemite",

"Electric, Steel",

30,

6000,

25,

35,

70,

supersonic,

tackle,

};

Pokemon tentacool =

{

"Tentacool",

"Water, Poison",

89,

45500,

40,

40,

35,

poison_sting,

supersonic,

};

Pokedex* pokedex =

prepend(&metapod,

prepend(&bellsprout,

prepend(&sudowoodo,

prepend(&magnemite,

prepend(&tentacool,

empty())))));

cout << "There is " << length(pokedex) << " Pokemon in the Pokedex" << endl;

cout << index(pokedex);

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions