您的位置:首页 > 其它

无名对象的作用

2015-11-07 18:40 211 查看
#include<iostream>
#include<stdlib.h>

using namespace std;
class Test
{
int m_data;
public:
Test(int i=0):m_data(i)
{
cout<<"Test()"<<m_data<<endl;
}

~Test(){
cout<<"~Test()"<<m_data<<endl;
}

};

int main(int argc,char**argv)
{
/*
Test();
cout<<"main()....."<<endl;
Test *pTest=new Test(10);//application 1 堆对象传参
delete pTest;
pTest=NULL;
*/
Test t=Test(10);  //application 2
Test t1=(Test)100;  //application 2
Test t2=10;//application 2  类型转换(优化)
Test t3(10);//t2,t3构建是等价
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: