注册 登录
编程论坛 C++ Builder

为什么我编的复数类不能执行除法运算了 ,能编译 ,不能生成

q236763612 发布于 2008-11-11 11:14, 1224 次点击
#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();
}
0 回复
1