1. 程式人生 > >同文件類外定義

同文件類外定義

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; }

同文件類外定義