포켓 몬스터 배틀 시뮬레이터를 만들고 있는데 배열 요소를 사용하여 클래스를 호출 할 수 있는지 알고 싶습니다.C++ 배열 요소를 사용하여 클래스를 호출하는 방법
#include <iostream>
#include <time.h>
#include <string>
using std::cout;
using std::endl;
using std::string;
string PokémonArray[] = { "Pikachu","Pidgey" };
class Pokémon {
public:
string basic_attack;
int basic_attack_dmg;
string getBasicAttackName() { return basic_attack; }
Pokémon() { ; }
};
class Pikachu : public Pokémon {
public:
Pikachu(){ basic_attack = "Whatever"; }
};
int main(){
int random_num;
string randEnemy;
srand(TIME(NULL));
random_num = rand() % 2; //Generates a random number between 0 and 1
randEnemy = PokémonArray[random_num]; //Sets randEnemy to be equal to the element 0 or 1 (generated above) of the array
(randEnemy) enemy; //Try to create the object 'enemy' calling a class using an element of the array
}
동일한 이름의 배열 요소를 사용하여 클래스를 호출하려면 어떻게해야합니까?
왜 포케몬 배열 대신 문자열 배열을 만드나요? – user2393256
임의의 숫자를 기반으로 임의의 적을 생성하려고합니까? 의미는 적의 두 가지 유형입니까? – Zebrafish