我正在使用类的RPG游戏我创建了一个结构调用字符,其中包含存储实例的ActionList*.GeneralPlayer是一个类,其中还有一堆其他玩家类继承它.这是我的头文件:
class Battle
{
public:
struct Character
{
char type;//monster or player?
bool alive;
void*instance;//pointer to instance
};
Battle(GeneralPlayer*,AbstractMonster*,int,int,int);
Battle(GeneralPlayer*, AbstractMonster*, int, int);
private:
Character *ActionList;
};
Run Code Online (Sandbox Code Playgroud)
我试图将GeneralPlayer*转换为void*.然而,似乎代码不像我想的那样工作.P和M是那些玩家类的指针数组.
Battle::Battle(GeneralPlayer*P, AbstractMonster*M, int a, int b, int c)
{
a = numP;
b = numM;
c = turn_limit;
ActionList = new Character[numP + numM];
P = new GeneralPlayer[numP];
for (int i = 0; i < numP; i++)
{
ActionList[i] = static_cast<void*>(P[i]);
ActionList[i].type = 'p';
}
for (int i = numP; i < …Run Code Online (Sandbox Code Playgroud)