哈哈发个运算符重载的例子: #include <iostream> using namespace std; class Complex {public: Complex() {real=0;imag=0;} Complex(double r,double i) {real=r;imag=i;} Complex operator + (const Complex &c); Complex operator - (Complex &c); Complex operator * (Complex &c); Complex operator / (Complex &c); void display(); private: double real; double imag; }; Complex Complex :: operator + (const Complex &c) { Complex M; M.real=real+c.real; M.imag=imag+c.imag; return M; } Complex Complex :: operator - (Complex &c) { Complex M; M.real=real-c.real; M.imag=imag-c.imag; return M; } Complex Complex :: operator * (Complex &c) { Complex M; M.real=real*c.real; M.imag=imag*c.imag; return M; } Complex Complex:: operator / (Complex &c) { Complex M; M.real=real/c.real; M.imag=imag/c.imag; return M; } void Complex ::display() {if(imag>0) cout<<"("<<real<<"+"<<imag<<"i"<<")"<<endl; else cout<<"("<<real<<imag<<"i"<<")"<<endl; } int main() {Complex c1(20,10),c2(10,-5),c3; c3=c1+c2; c3.display(); c3=c1-c2; c3.display(); c3=c1*c2; c3.display(); c3=c1/c2; c3.display(); return 0; }