class Some
{
int n;
public:
Some(int s){n=s;}
~Some(){
cout<< "destroy\n";
}
int ret(){return n;}
};
int main(int argc, char* argv[])
{
cout<<Some(111).ret()<<"\n";
cout<<"wait\n";
cin.get();
return 0;
}
运行
匿名对象只存在构造该对象的那行代码,离开构造匿名对象那行代码后立即调用析构函数。
标签:int,代码,Some,C++,对象,匿名,生存期,构造 From: https://blog.51cto.com/u_15487030/7522146