Pokemon! Here we have the classes of Pokemon.
class Pokemon{protected: int HP; int XP; std::string Name; std::string Type;public: virtual void Set(int, int, std::string, std::string); virtual void Get(int);};class Pikachu : public Pokemon{public: void Set(int HP, int XP, std::string Name, std::string Type); void Get(int);};class Togepi{public: void Set(int HP, int XP, std::string Name, std::string Type); void Get(int);};void Pikachu::Set(int HP, int XP, std::string Name, std::string Type){ Pikachu::HP = HP; Pikachu::XP = XP; Pikachu::Name = "Pikachu"; Pikachu::Type = "Electric";}void Togepi::Set(int HP, int XP, std::string Name, std::string Type){ Togepi::HP = HP * 2; Togepi::XP = XP / 2; Togepi::Name = "MY AWESOME KIDDO" Togepi::Type = "Normal";}void Pikachu::Get(int position){ switch(position) { case 1: std::cout << Pikachu::HP; break; case 2: std::cout << Pikachu::XP; break; case 3: std::cout << Pikachu::Name; break; case 4: std::cout << Pikachu::Type; break; }}void Togepi::Get(int position){ switch(position) { case 1: std::cout << Togepi::HP; break; case 2: std::cout << Togepi::XP; break; case 3: std::cout << Togepi::Name; break; case 4: std::cout << Togepi::Type; break; }}
And now I want to have a struct that contains a generic Pokemon class, with by using templates, I can change the class typename to different classes as I pleased...
template <typename T>struct GenericPKMN{ std::string AdditionalInfo; int NumberofPKMN; T Generic;};int main(){ GenericPKMN MyPikachu; MyPikachu.AdditionalInfo = "Testing my Pikachu..."; MyPikachu.NumberofPKMN = 1; //OH NO!! return 0;}
What should I put at the comment line? What else can I change to make my structs able to polymorph to different derived classes of a particular class?
Thanks in advance.