gpt4 book ai didi

c++ - 如何修复 C++ 错误 : expected unqualified-id

转载 作者:IT老高 更新时间:2023-10-28 12:45:30 26 4
gpt4 key购买 nike

我在第 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com