-3
我得到了這兩個結構中如何在C++中創建鏈表?
struct CamelZombie{
int hp;
int attack;
CamelZombie *next;
};
struct list_of_cz{
CamelZombie *head;
};
我做了一個函數來創建與給定值鏈表:
void createCamelZombie(list_of_cz *&pZ, int z_hp, int z_attack, int N){
pZ = new list_of_cz;
pZ->head->hp = z_hp;
pZ->head->attack = z_attack;
CamelZombie *temp1 = pZ->head;
CamelZombie *temp2 = NULL;
for (int i = 0; i < N - 1 ; i++){
temp2 = new CamelZombie;
temp2->hp = z_hp;
temp2->attack = z_attack;
temp1->next = temp2;
temp1 = temp2;
}
}
然後我把它的功能主要是這樣,但隨後的propram墜毀,不知道爲什麼。
list_of_cz *pZ = NULL;
createCamelZombie(pZ, z_hp, z_attack, N);
while (pList->head != NULL && pZ != NULL){
atPlant(numPlant(pList) - 1, pList)->hp -= pZ->head->attack;
if (atPlant(numPlant(pList) - 1, pList)->hp <= 0) deletePlant(numPlant(pList) - 1, pList);
int count = 0;
CamelZombie *z_temp;
z_temp = pZ->head;
while (z_temp){
if (count == 0) z_temp->hp -= allPlantAttack(pList, numPlant(pList) - 1);
else z_temp->hp -= allLaserAttack(pList); //trouble right here
if (z_temp->hp <= 0) deleteCamelZombie(pZ, count);
z_temp = z_temp->next;
count++;
}
似乎寫void createCamelZombie()
當像我錯過了什麼「導致編譯器告訴我,z_temp->hp
沒有價值。請幫幫我!
請逐字發佈錯誤消息! –
+ \t \t pZ-> head \t 0xcdcdcdcd {hp = ???攻擊= ???接下來= ??? } \t CamelZombie * 編譯器告訴我這個 –
*在你的問題***屬於**。 (就像你目前沒有提供的[minimal,complete,and verifiable example](https://stackoverflow.com/help/mcve)),關於這個看似奇怪的值,[你可能會發現** this ** (http://stackoverflow.com/questions/127386/in-visual-studio-c-what-are-the-memory-allocation-representations) – WhozCraig