class A{
public:
A(int p, char q):x(p), c(q){ cout << "constructor called" << endl; }
A(const A& a){x = a.x; c = a.c; cout << "copy constructor called" << endl;}
~A(){cout << "destructor called" << endl;}
private:
int x;
char c;
};
A a = A(1,'a');按照预想会先调用自定义构造函数生成临时对象,而后调用拷贝构造函数,最后会发生两次析构。
原文:http://blog.csdn.net/seanwang_25/article/details/39624467