问题及代码:
#include <iostream>
using namespace std;
//******************** begin ********************
class Complex
{
public:
Complex(double r=0,double i=0);
~Complex()
{
cout<<"destructed!"<<endl;
}
private:
double real;
double image;
};
Complex ::Complex(double r,double i)
{
real=r;
image=i;
cout<<"("<<real<<","<<image<<"i) is constructed!"<<endl;
cout<<"("<<real<<","<<image<<"i) is copy constructed!"<<endl;
}
//********************* end ********************
int main()
{
double real,image;
cin>>real>>image;
Complex c1(real,image);
Complex c2=c1;
return 0;
}
运行结果: