运算符重载时出现问题了
#include <iostream>
using namespace std;
class Complex
{private:
float r,i;
public:
Complex operator + (Complex &b);
Complex();
Complex(float &,float &);
void show();
};
Complex Complex::operator +(Complex &b)
{Complex temp;
temp.r=r+b.r;
temp.i=i+b.i;
return (temp);
}
Complex::Complex()
{r=0;i=0;}
Complex::Complex(float &a, float &b)
{r=a;i=b;}
void Complex::show()
{if(r<0)cout<<r<<"-"<<i<<"i"<<endl;
else if(r=0)cout<<r<<endl;
else cout<<r<<"+"<<i<<endl;
}
int main()
{ Complex c1(10,11),c2(12,13),c3;//编译时这里出错了
c3=c1+c2;
c3.show();
return 0;
}
using namespace std;
class Complex
{private:
float r,i;
public:
Complex operator + (Complex &b);
Complex();
Complex(float &,float &);
void show();
};
Complex Complex::operator +(Complex &b)
{Complex temp;
temp.r=r+b.r;
temp.i=i+b.i;
return (temp);
}
Complex::Complex()
{r=0;i=0;}
Complex::Complex(float &a, float &b)
{r=a;i=b;}
void Complex::show()
{if(r<0)cout<<r<<"-"<<i<<"i"<<endl;
else if(r=0)cout<<r<<endl;
else cout<<r<<"+"<<i<<endl;
}
int main()
{ Complex c1(10,11),c2(12,13),c3;//编译时这里出错了
c3=c1+c2;
c3.show();
return 0;
}
这里是报错的消息
no matching function for call to `Complex::Complex(int, int)'
Complex::Complex(float&, float&)
Complex::Complex()
Complex::Complex(float&, float&)
Complex::Complex()
我想是不是创建对象是把"10"看成int形,那么我改为"10F"这样还是不行