include
class Pokemon {
public:
// コンストラクタ
Pokemon(const std::string& nickname) {
this->nickname_ = nickname;
// nickname_ = nickname; と省略できる
}
// デストラクタ
virtual ~Pokemon() {
}
virtual void attack() = 0;
protected:
std::string nickname_;
};
class Pikachu : public Pokemon {
public:
Pikachu(const std::string& nickname) : Pokemon(nickname) {
}
virtual ~Pikachu() {
}
void attack() override {
std::cout << nickname_ << “の十万ボルト!” << std::endl;
}
};
class Zenigame : public Pokemon {
public:
Zenigame(const std::string& nickname) : Pokemon(nickname) {
}
virtual ~Zenigame() {
}
void attack() override {
std::cout << nickname_ << “のハイドロポンプ!” << std::endl;
}
};
int main() {
int i;
Pokemon* monsters[2];
monsters[0] = new Pikachu(“サトシのピカチュウ”);
monsters[1] = new Zenigame(“サトシのゼニガメ”);
std::cin >> i;
if (i >= 0 && i < 2) { monsters[i]->attack();
}
delete monsters[0];
delete monsters[1];
}