你的构造函数里面的赋值写反了应该是real=r;imag=i;。。粗心问题。。。
给好评哦,亲=。=
#include
using namespace std;
class complex
{
double real, imag;
public:
complex(double r=0, double i = 0)
{
real = r;
imag = i;
}
complex(complex &other)
{
real += other.real;
imag += other.imag;
}
void show()
{
if(imag>0)
{
cout << real;
cout <<"+"<< imag << "i" << endl;}
else
{ cout << real;
cout << imag << "i" << endl;}
}
};
int main()
{
double m,n;
cout<<"输入复数的实部和虚部:"<
complex c1(m, n);
complex c2(c1);
c1.show();
return 0;
}