简体   繁体   English

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

[英]error: expected unqualified-id (C++)

I am trying to create a basic text-based adventure game in C++. 我正在尝试用C ++创建一个基于文本的基本冒险游戏。 Here is one of my classes. 这是我的课程之一。

#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;
        }

The problem I am having is that it keeps giving me an error on line 9 that reads- error: expected unqualified-id before 'int'. 我遇到的问题是它在第9行给我一个错误,读取错误:在'int'之前预期的unqualified-id。 It is giving me another error on line 19 that reads- error: expected unqualified-id before 'void'. 它在第19行给出了另一个错误,即读取错误:在'void'之前预期的nonqualified-id。 I cannot figure out what the problem is, help would be appreciated. 我无法弄清楚问题是什么,帮助将不胜感激。

You've got the return type and class name wrong ways. 你有错误的返回类型和类名。

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

ditto for goblinFight::void defendGoblin() 同上goblinFight::void defendGoblin()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM