#include <iostream>
using namespace std;
class Person {
private:
int age;
public:
//普通构造
Person() {
cout << "无参构造函数" << endl;
}
//有参构造函数
Person(int a) {
cout << "有参构造函数" << endl;
}
//拷贝构造函数,将传入的对象身上所有属性拷贝到这个类身上
Person(const Person &person) {
this->age = person.age;
cout << "拷贝构造函数" << endl;
}
//析构函数
virtual ~Person() {
cout << "析构函数" << endl;
}
};
void test() {
//对象创建,构造函数执行,对象销毁,析构函数执行
Person person;
}
int main() {
//括号法
Person person;
Person p2(10);
Person p3(p2);
//显示法
Person p4;
Person p5 = Person(40);
Person p6 = Person(p2);
//隐式转换法
Person p7 = 10;
Person p8 = p7;
}