我在第 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;
...但是在你的类定义的末尾应该有一个:
...
private:
string theWord;
}; // <-- Semicolon should be at the end of your class definition
关于c++ - 如何修复 C++ 错误 : expected unqualified-id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10135244/