C++复制控制
class Person{protected: string name; char sex; int age;public: Person(void) { cout<<"In Person(void)"<<endl; } ~Person(void) { cout<<"In ~Person(void)"<<endl; } Person(string name, char sex, int age) { cout<<"In Person(string name, char sex, int age)"<<endl; this->name = name; this->sex = sex; this->age = age; } virtual void printInfo(void) { cout<<"name:"<<name<<endl<<"age:"<<age<<endl; cout<<"sex:"; if(sex == 0) { cout<<"Male"; }else { cout<<"Female"; } cout<<endl; }};class Employee:public Person{private: int emp_num; int salary; string job; public: Employee(const Employee &e) { this->age = e.age + 10; this->emp_num = this->emp_num + 2; this->job = e.job; this->name = e.name; this->salary = e.salary; this->sex = e.sex; cout << "In Employee(const Employee &e)"<<endl; } Employee(void) { cout<<"In Employee(void)"<<endl; } ~Employee(void) { cout<<"In ~Employee"<<endl; } Employee(string name, char sex, int age, int emp_num, int salary, string job):Person(name, sex, age) { cout<<"In Employee(string name, char sex, int age, int emp_num, int salary, string job)"<<endl; this->emp_num = emp_num; this->salary = salary; this->job = job; } void operator=(Employee e) { this->age = e.age + 3; this->emp_num = this->emp_num + 1; this->job = e.job; this->name = e.name; this->salary = e.salary; this->sex = e.sex; cout << "In Employee ="<<endl; } void printInfo(void) { cout<<"name:"<<name<<endl<<"age:"<<age<<endl; cout<<"sex:"; if(sex == 0) { cout<<"Male"; }else { cout<<"Female"; } cout<<endl<<"emp_num:"<<emp_num<<endl<<"salary:"<<salary<<endl<<"job:"<<job<<endl; }};int _tmain(int argc, _TCHAR* argv[]){ Employee e_1("zhb", 0, 25, 20, 5000, "enigeer"); Employee e_2("pf", 0, 25, 1000, 2000, "unknown"); e_1 = e_2; system("pause"); return 0;}