esh*_*esh 0 c++ constructor copy
class X
{
int i;
public:
X(int m) : i(m) {};
X(const X& x)
{
//cout "copy constructor is called\n";
}
const X opearator++(X& a,int)
{
//cout "X++ is called\n";
X b(a.i);
a.i++;
return b;
}
void f(X a)
{ }
};
int main()
{
X a(1);
f(a);
a++;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这里当调用函数'f'时,复制构造函数将按预期调用.在++的情况下,调用operator ++函数,但是当它返回"不调用复制构造函数"时.为什么"从函数'运算符++'返回时没有调用复制构造函数?