4.24

发布时间 2023-04-24 20:50:32作者: 刘梦磊

#include <iostream>
using namespace std;
class Person {
public:
int age;
Person() {
cout << "默认构造函数调用" << endl;
}
Person(int a) {
age = a;
cout << "有参构造函数调用" << endl;
}
~Person() {
cout << "析构函数调用" << endl;
}
Person(const Person& p) {
age = p.age;
cout << "拷贝构造函数调用" << endl;
}
};
void test1() {
Person p1(20);
Person p2(p1);
}
void dowork(Person p) {

}
void test2() {
Person p;
dowork(p);
}
Person dowork2() {
Person p1;
cout << (int*)&p1 << endl;
return p1;
}
void test3() {
Person p = dowork2();
cout << (int*)&p << endl;
}
int main() {
test3();
system("pause");
return 0;
}