嘿,我只是想知道這些警告中的任何一個會導致.exe在啓動時崩潰。 下面是警告:警告導致.exe中的錯誤?
Warning 1 warning C4244: '=' : conversion from 'double' to 'int', possible loss of data c:\users\conor\documents\college\dkit - year 2 - repeat\dkit - year 2 - semester 1 - repeat\games programming\maroonedca2\maroonedca2\stats.cpp 54 1 MaroonedCA2
Warning 2 warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data c:\users\conor\documents\college\dkit - year 2 - repeat\dkit - year 2 - semester 1 - repeat\games programming\maroonedca2\maroonedca2\player.cpp 75 1 MaroonedCA2
Warning 3 warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data c:\users\conor\documents\college\dkit - year 2 - repeat\dkit - year 2 - semester 1 - repeat\games programming\maroonedca2\maroonedca2\player.cpp 92 1 MaroonedCA2
Warning 4 warning C4018: '<' : signed/unsigned mismatch c:\users\conor\documents\college\dkit - year 2 - repeat\dkit - year 2 - semester 1 - repeat\games programming\maroonedca2\maroonedca2\inventory.cpp 63 1 MaroonedCA2
1個
int stats[SIZE];
stats[0] = Status.health;
stats[1] = Status.strength;
stats[2] = Status.hitpoints;
stats[3] = Status.armour;
stats[4] = Status.luck;
運氣是一張雙人牀和尚未鑄造。
int Player :: hitPoints()
{
srand(time(0)); // seed random number generator based on current time
int randomNumber= rand(); // generate random number
int hitPoints = (randomNumber% 15) + 1; // get a number between 1 and 20
return hitPoints;
}
int Player :: fatigue()
{
srand(time(0)); // seed random number generator based on current time
int randomNumber= rand(); // generate random number
int fatigue = (randomNumber% 5) + 1; // get a number between 1 and 5
return fatigue;
}
for (int i= 0; i< inventory.size(); ++i)
cout<< inventory[i] << endl;
}
cout << "\n-----------------------------------------\n";
不是我能看到的。但是你應該知道這些警告是關於什麼的,它們很容易修復,並且最好不要養成編寫代碼的習慣。 – PeterJ
好吧,警告對生成的代碼沒有影響,所以沒有。但是,警告可能表明您的代碼中存在可能導致崩潰的錯誤。 (或者你可能有這樣一個錯誤,並沒有警告。)上述警告比直接導致崩潰的東西更多地暗示數據丟失,但是可能存在環路控制或數組索引導致崩潰的問題。 (很好的做法是檢查每個警告,理解它發佈的原因,如果它是一個「非問題」,則插入一個明確的演員或其他任何東西來使其靜音,並表明您理解問題。) –