为什么我编的复数类不能执行除法运算了 ,能编译 ,不能生成
不能执行除法运算了 有生成错误 哪位大哥能帮帮我哈哈!#include<iostream>
#include<cassert>
using namespace std;
class Complex
{
private:
int Real ;
int Image;
public:
Complex(int r=0, int i=0)
:Real(r),Image(i)
{}
~Complex()
Real=a.Real ;
Image=a.Image ;
}
Complex& operator=(const Complex& a)
{
assert(this!=&a);
Real=a.Real;
Image=a.Image ;
return *this;
}
void print()
{
cout<<Real<<"+"<<Image<<"i"<<endl;
}
friend Complex Add(const Complex& a, const Complex& b);
friend Complex Div(const Complex& a, const Complex& b);
};
Complex Add( const Complex& a, const Complex& b)
{
return Complex (a.Real +b.Real ,a.Image+b.Image );
}
Complex Div ( const Complex& a , const Complex& b)
{
assert( b.Real *b.Image !=0);
return Complex ( (a.Real *b.Real +a.Image*b.Image)/(b.Real*b.Real +b.Image*b.Image), (a.Image *b.Real -a.Real *b.Image)/(b.Real*b.Real +b.Image*b.Image ));
}
int main ()
{
Complex a,b,c;
a.SetComplex ();
b.SetComplex ();
c=Div (a,b);
c.print();
}