同文件類外定義
阿新 • • 發佈:2018-06-26
main set pre teacher iostream div AC clu return
#include <iostream> #include <string> using namespace std; class teacher{ public: void setName(string _name); string getName(); void setGender(string _gender); string getGender(); void teach(); private: string strName; string strGender; }; void teacher::setName(string_name){ strName=_name; } string teacher::getName(){ return strName; } void teacher::setGender(string _gender){ strGender=_gender; } string teacher::getGender(){ return strGender; } void teacher::teach(){ cout << "上課" << endl; } int main() { teacher t; t.setName("A"); t.setGender("女"); cout << t.getName() + " " << t.getGender() << endl; t.teach(); return 0; }
同文件類外定義