无名对象的作用
#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;
}

浙公网安备 33010602011771号