#include <iostream>
using namespace std;
class Teacher
{
public:
Teacher();
Teacher(int age);
~Teacher();
Teacher(const Teacher& teacher);
void SetAge(int age);
int GetAge();
private:
int age{ 0 };
};
Teacher::Teacher()
{
cout << "无参构造函数" << endl;
}
Teacher::Teacher(int age)
{
this->age = age;
cout << "有参构造函数" << endl;
}
Teacher::~Teacher()
{
}
Teacher::Teacher(const Teacher& teacher)
{
cout << "拷贝构造函数" << endl;
}
void Teacher::SetAge(int age)
{
this->age = age;
}
int Teacher::GetAge()
{
return this->age;
}
void OperateTeacher(Teacher t)
{
t.SetAge(20);
}
Teacher GetTeacher()
{
Teacher t(20);
return t;
}
int main()
{
/*Teacher t;
t.SetAge(30);*/
//Teacher t2 = t; //第一种:执行拷贝构造函数
//Teacher t2(t); //第二种:执行拷贝构造函数
//OperateTeacher(t); //第三种:执行拷贝构造函数
GetTeacher();//第四种:执行拷贝构造函数
/*cout << t.GetAge() << endl;*/
}