类 对象生存周期
2016-09-16 16:58
225 查看
类 对象生存周期
Test operator=(const Test &res)
{
cout << "operator=(const Test &)" << endl;
return *this;
}
Test GetTest(Test &t)
{
int value = t.GetValue();
//Test tmp(value);
//return tmp;//对象 开辟内存,构造5
return Test(value);
}
Test operator=(const Test &res)
{
cout << "operator=(const Test &)" << endl;
return *this;
}
Test GetTest(Test &t)
{
int value = t.GetValue();
Test tmp(value);
return tmp;//对象 开辟内存,构造5
//return Test(value);
}
/*************************20160915C++*************************/ #include<iostream> using namespace std; /*对象生存周期 c <=4 eax >4 <=8 eax edx 返回对象,总产生临时量 C++ 空 1 *临时对象不在赋值构造同类型新对象时产生 */ class Test { public: Test(int m=10) { //cout << this << endl; cout << "Test(int)" << endl; ma = m; } ~Test(){ cout << "~Test()" << endl; } Test(const Test &res) { cout << "Test(const Test &)" << endl; } Test operator=(const Test &res) { cout << "operator=(const Test &)" << endl; return *this; } int GetValue() { return ma; } private: int ma; }; Test GetTest(Test &t) { int value = t.GetValue(); //Test tmp(value); //return tmp;//对象 开辟内存,构造5 return Test(value); } int main() { Test t1(20); //Test t2 = GetTest(t1); /* Test t2; t2 = GetTest(t1);*/ return 0; }
Test operator=(const Test &res)
{
cout << "operator=(const Test &)" << endl;
return *this;
}
Test GetTest(Test &t)
{
int value = t.GetValue();
//Test tmp(value);
//return tmp;//对象 开辟内存,构造5
return Test(value);
}
Test operator=(const Test &res)
{
cout << "operator=(const Test &)" << endl;
return *this;
}
Test GetTest(Test &t)
{
int value = t.GetValue();
Test tmp(value);
return tmp;//对象 开辟内存,构造5
//return Test(value);
}
相关文章推荐
- C++ 临时对象的生存周期
- 单元线程对象的生存周期
- C++中实例化出的对象的生存周期
- 引用计数自动管理对象的生存周期
- .NET Remoting开发系列:(二) 对象生存周期管理
- 远程对象的生存周期问题(flex中的对象的生存周期和服务端的周期是一样的么?)
- C++——面向对象(三)——各种对象的生存周期
- 引用计数自动管理对象的生存周期
- Python浅复制中对象生存周期实例分析
- C++对象的生存周期
- JAVA基础语法、面向对象、了解java对象的生存周期(Object、修饰符、数组、枚举、接口、抽象类)
- C++对象的生存周期
- Java虚拟机之Java对象生存周期是否存活
- Python浅复制中对象的生存周期
- 为什么有时候C++运算符重载要返回引用,附对象生存周期
- C++关于对象的生存周期
- .Net Remoting 对象生存周期(3)
- Asp.net的应用程序对象和页面生存周期
- 面向对象基础知识(3)--对象生存周期
- Spring对象生存周期(Scope)的分析