对于下面的代码,Fun() 返回一个 Test 类型的临时对象
#include<iostream>
#include<typeinfo>
using namespace std;
class Test
{
private:
int x;
static int count;
public:
Test(int i=0 ) {cout<<"sumit";}
Test(const Test& rhs) : x(rhs.x) { ++count; cout<<"sum"; }
static int getCount() { return count; }
};
int Test::count = 0;
Test fun()
{
Test ob(7);
return ob;
}
int main()
{
Test a=fun();
cout<<typeid(fun()).name();
cout<< Test::getCount();
return 0;
}
未进行静态复制
代码的输出:
构造函数 4Test