#include #include "NewPlayerT.h" using namespace std; class BarbarianT : public FighterT { public: BarbarianT(string newName): FighterT{newName + " barbarian " } {}; string Role() const override { return "Barbarian"; } int Rage() const { return rage; } int Chaos() const { return chaos; } private: int rage{999}; int chaos{-10}; }; void TellAboutPlayer(NewPlayerT * player); int main() { FighterT fighter("Fred"); WizardT wizard("Walt"); MonkT monk("Morty"); BarbarianT barbarian("Arnold"); // slice cout << "About to slice" << endl; FighterT newFighter = barbarian; cout << "The barbarian thinks he is a " << newFighter.Role() << endl; // can't do this. //BarbarianT newBarbarian = fighter; cout << endl << endl; cout << "The players tell us about themselves" << endl; TellAboutPlayer(&fighter); TellAboutPlayer(&wizard); TellAboutPlayer(&monk); TellAboutPlayer(&barbarian); return 0; } void TellAboutPlayer(NewPlayerT * player){ cout << "This is " << player->Name() << endl; cout << "They are a " << player->Role() << endl; // cout << "\t Magic: " << player->Magic() << endl; //FighterT * fighterPointer = dynamic_cast (player); FighterT * fighterPointer = static_cast (player); if (nullptr != fighterPointer) { cout << "\t Strength: " << fighterPointer->Strength() << endl; } //BarbarianT * barbarianPointer = dynamic_cast(player); BarbarianT * barbarianPointer = static_cast(player); cout << "\t Rage: " << barbarianPointer->Rage() << endl; cout << "\t Chaos: " << barbarianPointer->Chaos() << endl; cout << endl; }