我創建了一個類對象的指針指針,當我嘗試使用指向它的seg-fault創建一個新對象時。爲什麼會發生?爲什麼這個指針初始化段錯誤?
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);
你能提供你的士兵構造嗎? – 2009-01-28 13:22:37