error: no matching function for call to 'Complex::Complex()'|
#include<iostream>using namespace std;
class Complex
{
private:
int real,imag;
protected:
public:
Complex(int r,int i);
~Complex();
void show();
friend ostream &operator<<(ostream &os,const Complex &f);
friend istream &operator>>(istream &is,Complex &f);
Complex operator+(Complex &obj2);
Complex operator-(Complex &obj2);
Complex operator*(Complex &obj2);
};
Complex Complex::operator+(Complex &obj2)
{
Complex temp;//这里有错???????????????????????????????????????????????
temp.real=this->real+obj2.real;
temp.imag=this->imag+obj2.imag;
return temp;
}
Complex Complex::operator-(Complex &obj2)
{
this->real-=obj2.real;
this->imag-=obj2.imag;
return *this;
}
Complex Complex::operator*(Complex &obj2)
{
this->real*=obj2.real;
this->imag*=obj2.imag;
return *this;
}
Complex::Complex(int r=0,int i=0):real(r),imag(i)
{
cout<<real<<"+"<<imag<<"i"<<endl;
cout<<"storage space allocation."<<endl;
}
Complex::~Complex()
{
cout<<"delete space finished!"<<endl;
}
void Complex::show()
{
cout<<real<<"+"<<imag<<"i"<<endl;
}
ostream &operator<<(ostream &os,const Complex &f)
{
os<<f.real<<"+"<<f.imag<<"i"<<endl;
}
istream &operator>>(istream &is,Complex &f)
{
is>>f.real>>f.imag;
return is;
}
int main()
{
Complex obj,obj2;
cin>>obj>>obj2;
cout<<obj<<obj2;
cout<<obj+obj2<<endl<<obj-obj2<<endl<<obj*obj2;
return 0;
}