-2
我想C++,仍然學生在uni,無法找到錯誤來自哪裏。有人可以幫忙嗎?需要調試'預期的非限定id之前')'令牌',第一次C++用戶
class M() {
static bool m() {
cout << "Hello, do you want to tell me your name (y or n)";
char answer = 0;
int times = 1;
while(times < 3) {
cin >> answer;
switch(answer){
case 'y' :
return true;
case 'n' :
return false;
default :
cout << "I am sorry, I don't understand that.";
times += 1;
}
cout << "Your time's up.";
return false;
}
}
}
int main() {
M::m();
};
權,但是如何創建給定類的實例,因爲除此之外,main()會報告沒有創建M的實例。 「無法調用成員函數'bool M :: m()'without object」 –
我已經更新了答案。 – Izhaki
謝謝,我不知道語法如何,事情開始有意義,只是std :: cin/cout實際上是Class :: methodname?謝謝您的幫助 –