gpt4 book ai didi

c++ - 错误 : expected unqualified-id (C++)

转载 作者:行者123 更新时间:2023-11-28 02:55:31 25 4
gpt4 key购买 nike

我正在尝试用 C++ 创建一个基本的基于文​​本的冒险游戏。这是我的一门课。

#include "goblinFight.h"
#include <iostream>
#include <cmath>
#include <string>

using namespace std;


goblinFight::int fightGoblin()
{
cout << "A goblin attacks you! You: " << endl;
cout << "Raise your shield. (1)" << endl;
cout << "Take a step back. (2)" << endl;
cout << "Slash at it with your sword. (3)" << endl;
cin >> UI;
return UI;
}

goblinFight::void defendGoblin()
{
switch(UI){
case 1: cout << "The goblin slashes at your with his " << goblinWeapon << ", but it bounces off your shield." << endl;
playerShieldHealth -= 1;
break;

case 2: cout << "The goblin steps forward..." << endl;
switch(playerShieldHealth){
case 0: playerShieldHealth += 2;
break;
case 1: playerShieldHealth += 1;
break;}
break;

case 3: srand(time(0));
fightDice = rand() % 3;
switch(fightDice){
case 0: cout << "You strike the goblin! He bellows with rage!" << endl;
goblinHealth -= 1;
break;
case 1: cout << "You strike the goblin! He screams in pain!" << endl;
goblinHealth -= 1;
break;
case 2: cout << "You miss the goblin! He cackles at your ineptness." << endl;
break;
}
break;
}

我遇到的问题是它一直在第 9 行给我一个错误:错误:'int' 之前的预期非限定 ID。它在第 19 行给了我另一个错误,上面写着 - error: expected unqualified-id before 'void'。我无法弄清楚问题是什么,将不胜感激。

最佳答案

你有错误的返回类型和类名。

goblinFight::int fightGoblin() 应该是 int goblinFight::fightGoblin()

同上 goblinFight::void defendGoblin()

关于c++ - 错误 : expected unqualified-id (C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22090498/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com