错误:预期的unqualified-id(C ++)

时间:2014-02-28 09:01:35

标签: c++ class int void

我正在尝试用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'之前预期的unqualified-id。它在第19行给出了另一个错误,即读取错误:在'void'之前预期的nonqualified-id。我无法弄清楚问题是什么,帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

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

goblinFight::int fightGoblin()应为int goblinFight::fightGoblin()

同上goblinFight::void defendGoblin()