C ++错误:预期的未限定ID [英] C++ error: expected unqualified-id

查看:406
本文介绍了C ++错误:预期的未限定ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到一个错误错误:第6行上的预期未限定ID之前{'token'。

I'm getting an error "error: expected unqualified-id before '{' token" on line 6.

我无法辨别错误。 / p>

I can't tell what's wrong.

#include <iostream>

using namespace std;

class WordGame;
{
public:

    void setWord( string word )
    {
        theWord = word;
    }
    string getWord()
    {
        return theWord;
    }
    void displayWord()
    {
        cout << "Your word is " << getWord() << endl;
    }
private:
    string theWord;
}


int main()
{
    string aWord;
    WordGame theGame;
    cin >> aWord;
    theGame.setWord(aWord);
    theGame.displaymessage();

}


推荐答案

这里没有分号:

class WordGame;

...但在类定义的末尾应该有一个:

...but there should be one at the end of your class definition:

...
private:
    string theWord;
}; // <-- Semicolon should be at the end of your class definition

这篇关于C ++错误:预期的未限定ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆