1
我正在寫一個非常簡單的遊戲模擬器(不使用類)。從main()函數中,我成功地訪問了我的一個函數,但另一個函數調用會拋出錯誤:'沒有匹配函數調用simGame'。 任何想法爲什麼發生這種情況? 代碼:簡單的C++遊戲模擬器 - 沒有匹配的函數調用
...
float rollDice() {
default_random_engine randomGenerator(time(NULL));
uniform_real_distribution<float> rollDice(0.0f, 1.0f);
float roll = rollDice(randomGenerator);
return roll;
}
string simGame(string p1, string p2, int p1Health, int p2Health, int p1Attack, int p2Attack) {
// Game State
bool gameOver = false;
float attack = rollDice();
int pl1 = 0;
int pl2 = 1;
int turn = pl1;
int defenderHealth = p2Health;
int attackerAttack = p1Attack;
while ((p1Health > 0) && (p2Health > 0)) {
if (attack > 0.3) {
defenderHealth -= attackerAttack;
}
turn = -turn + 1;
if (turn == 0) {
defenderHealth = p2Health;
attackerAttack = p1Attack;
} else {
defenderHealth = p1Health;
attackerAttack = p2Attack;
}
}
turn = -turn + 1;
if (turn == 0) {
return p1;
} else {
return p2;
}
return 0;
}
int setHealth(int botNum, int botHealth) {
int totalHealth = botNum * botHealth;
return totalHealth;
}
int main() {
// bot types
int drWhosAndCompanions;
int ricksAndMortys;
// Attributes
int rmHealth = 10;
int dcHealth = 15;
int rmAttack = 15;
int dcAttack = 10;
int totalRMHealth;
int totalDocHealth;
cout << "How many Ricks and Mortys?" << endl;
cin >> ricksAndMortys;
cout << "How many Dr Whos and Companions?" << endl;
cin >> drWhosAndCompanions;
// Starting Vals
totalRMHealth = setHealth(ricksAndMortys, rmHealth);
totalDocHealth = setHealth(drWhosAndCompanions, dcHealth);
cout << "You have chosen " << ricksAndMortys << " Ricks and Mortys and " << drWhosAndCompanions << " Dr. Whos and Companions.\n";
string res;
res = simGame(ricksAndMortys, drWhosAndCompanions, rmHealth, dcHealth, rmAttack, dcAttack);
return 0;
}
我不能相信,我得到了 - 從JS和Python來使靜態類型有點迷失方向。 – cc77
是的。它也發生在我身上:) –