我创建了一个类对象的指针,当我尝试使用指针创建一个新对象时,它会出现段错误。为什么会这样?
struct Level
{
int SoldierCount;
Soldier **soldier;
int taskCount;
int *taskPercentage;
int *taskBitmapX;
int *taskBitmapY;
}level;
void createMap()
{
//Input and Declartion of various variabls goes here
level.soldier = new Soldier* [level.SoldierCount];
//Seg Faults Here
level.Soldier[i] = new Soldier(initX, initY, initDirection, steps);
}
士兵类构造函数:
Soldier(int, int, int, int);