拷贝构造的问题
#include <iostream.h>
class X{
public:
X(int);
X(X&);
~X();
};
X::X(int s){ cout <<"create a X object with " <<s <<endl; }
X::X(X& x){ cout <<"create a X object from other X object\n"; }
X::~X(){ cout <<"erase a object\n"; }
void f(X x)
{
cout <<"call a func with para X object\n";
return ;
}
int main()
{
X a(1);
f(a);//这里执行了拷贝构造,没有问题
f(X(2);//这里没有执行拷贝构造,VC,为什么?
return 0;
}