求高手帮忙! c++ 问题?
求高手帮忙! c++ 问题?#include <iostream>
using namespace std;
class Complex
{
private:
float Real,Image;
public:
Complex(float r = 0,float i = 0)
{
Real = r;
Image = i;
}
void Show(int i)
{
cout<<"c"<< i << "=" << Real << "+" << Image << "i" << endl;
}
Complex operator+ (Complex &c);
Complex operator- (Complex &c);
void operator= (Complex &c);
};
void Complex::operator= (Complex &c)
{
Real = c.Real;
Image = c.Image;
return ;
}
Complex Complex::operator+ (Complex &c)
{
Complex t;
t.Real = Real + c.Real;
t.Image = Image + c.Image;
return t;
}
Complex Complex::operator- (Complex &c)
{
Complex t;
t.Real = Real - c.Real;
t.Image = Image - c.Image;
return t;
}
int main(void)
{
Complex c1(20,20),c2(30,50),c3;
c1.Show(1);
c2.Show(2);
c3 = c1 + c2;
c3.Show(3);
return 0;
}
80: error: no match for ‘operator=’ in ‘c3 = (((Complex&)(& c2)))’
chongzai.cpp:36: note: candidates are: void Complex::operator=(Complex&)