运算符重载问题求助
#include <iostream.h>class complex
{
public:
complex(double x,double y);
complex operator+(complex x);
complex operator-(complex x);
void display();
private:
double real;
double imange;
};
complex::complex(double x=0,double y=0) {real=x,imange=y;}
complex complex::operator+(complex z)
{
complex zz;
zz.real=z.real+real;
zz.imange=z.imange+imange;
return complex(zz.real,zz.imange);
};
void complex::display()
{
cout<<"("<<real<<","<<imange<<")"<<endl;
};
void main()
{
complex c1(3,5),c2(2,3),c3;
cout<<"c1=";c1.display();
cout<<"c2=";c2.display();
c3=c1+c2;
cout<<"c3=c1+c2=";c3.display();
}
66.cpp
F:\66\66.cpp(16) : error C2512: 'complex' : no appropriate default constructor available
F:\66\66.cpp(27) : error C2512: 'complex' : no appropriate default constructor available
Error executing cl.exe.
按照教程的演示编写的,可编译出错,不知道什么原因,请高手帮忙分析下。