求解呀大佬们,为什么test01在创建变量p时没有使用构造函数,也没有对临时对象析构,我认为test01和test02使用的析构函数应该一样才对吧。
为什么test01在创建变量p时没有使用构造函数,也没有对临时对象析构,我认为test01和test02使用的析构函数应该一样才对吧。
#include<iostream>
using namespace std;
class Person
{
int m_age;
public:
Person()
{
cout << "默认构造" << endl;
}
Person(int age):m_age(age)
{
cout << "有参构造" << endl;
}
Person(const Person &p)
{
m_age = p.m_age;
cout << "复制构造函数" << endl;
}
~Person()
{
cout << "析构构造" << endl;
}
};
Person dowork()
{
Person p1;
return p1;
}
void test01()
{
Person p = dowork();
}
void test02()
{
Person p;
p = dowork();
}
int main()
{
cout << "test01 :" << endl;
test01();
cout << "test02 :" << endl;
test02();
system("pause");
return 0;
}
#include<iostream>
using namespace std;
class Person
{
int m_age;
public:
Person()
{
cout << "默认构造" << endl;
}
Person(int age):m_age(age)
{
cout << "有参构造" << endl;
}
Person(const Person &p)
{
m_age = p.m_age;
cout << "复制构造函数" << endl;
}
~Person()
{
cout << "析构构造" << endl;
}
};
Person dowork()
{
Person p1;
return p1;
}
void test01()
{
Person p = dowork();
}
void test02()
{
Person p;
p = dowork();
}
int main()
{
cout << "test01 :" << endl;
test01();
cout << "test02 :" << endl;
test02();
system("pause");
return 0;
}
...全文
相关推荐
p5-test-01:我的第一个p5.js和github页面测试
p5-test-01 我的第一个p5.js和github页面测试
在实例化对象的过程中需要在内存中开辟空间,这其中就包括栈内存和对内存。
在实例化对象的过程中需要在内存中开辟空间,这其中就包括栈内存和对内存。在实例化对象的过程中需要在内存中开辟空间,这其中就包括栈内存和对内存。
Python面向对象之类和对象属性的增删改查操作示例
主要介绍了Python面向对象之类和对象属性的增删改查操作,结合实例形式分析了Python面向对象相关的类与对象属性常见操作技巧,需要的朋友可以参考下
ZJ070NA-01P(Pre V01)2012-01-11.pdf
ZJ070NA-01P规格书
TQA-6450-P10S-01-R Four Corner Test Report For OS6450-P10S
TQA-6450-P10S-01-R Four Corner Test Report For OS6450-P10S



