[英]Can Someone Explain Why My Getter Function Doesn't Call?
我正在編寫一些代碼來創建一個學生 class 和一個允許用戶輸入和顯示信息的菜單。 我在讓我的 GetName function 調用時遇到了一些問題。 這是我的代碼:
#include <iostream>
using namespace std;
class Student {
string FirstName, LastName, Birthday;
int MNumber, Age;
float GPA;
public:
void GetName(){
cout << "Please enter your First Name." << endl;
cin >> FirstName;
cout << "Please enter your Last Name." << endl;
cin >> LastName;
cout << FirstName << ", " << LastName << endl;
}
};
int main () {
Student GetName;
return 0;
}
}
您沒有在主程序中調用“Getname”方法。
#include <iostream>
using namespace std;
class Student {
string FirstName, LastName, Birthday;
int MNumber, Age;
float GPA;
public:
void GetName(){
cout << "Please enter your First Name." << endl;
cin >> FirstName;
cout << "Please enter your Last Name." << endl;
cin >> LastName;
cout << FirstName << ", " << LastName << endl;
}
};
int main () {
Student getName;
getName.GetName();
return 0;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.