它只运行 main,输出“输入一个单词”,但完全忽略了对象/类
我是新手,抱歉,如果这是一个不恰当的简单问题。这在发布和调试模式下都会发生
#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()
{
cout << "Enter a word" << endl;
string aWord;
WordGame theGame;
cin >> aWord;
theGame.setWord(aWord);
theGame.displayWord();
}