如何修复C ++错误:预期的unqualified-id [英] How to fix C++ error: expected unqualified-id
本文介绍了如何修复C ++错误:预期的unqualified-id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在第6行遇到此错误:
I'm getting this error on line 6:
error: expected unqualified-id before '{' token
我不知道怎么了.
#include <iostream>
using namespace std;
class WordGame;
{ // <== error is here on line 6
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 ++错误:预期的unqualified-id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文