#include <iostream>
using namespace std;
class Person{
public:
Person()
{
cout<<"Person的无参调用"<<endl;
}
Person(int age)
{
m_age=age;
cout<<"Person的有参调用"<<endl;
}
Person(const Person &p)
{
m_age=p.m_age;
cout<<"Person的拷贝构造函数调用"<<endl;
}
~Person()
{
cout<<"Person的析构函数的调用"<<endl;
}
int m_age;
};
Person test()
{
Person p1;
return p1;
}
void func()
{
Person p = test();
}
int main()
{
func();
}
上述是代码,在visual stdio 2019 运行结果是
而在Linux下是
我又试了其他编译器sublime text 3
vscode同样也是
这是为啥啊