class Complex { public: explicit Complex(double real, double imaginary = 0) : real_(real), imaginary_(imaginary) { } Complex& operaor+=(const Complex& o) { real_ += o._real_; imaginary_ += o.imaginary_; return *this; } Complex& operator++() { ++real_; return *this; } const Complex operator++(int)// to avoid this expression: a++++ { Complex tmp(*this); ++*this; return tmp; } ostream& Print(ostream& os) const { return os << ....; } private: double real_, imaginary_; }; const Complex operator+(const Complex& a, const Complex& b) { Complex ret(a); ret += b; return ret; } ostream& operator<<(ostream& os, const Complex& c) { return c.Print(os); }
My simple implementation for class string:
https://github.com/yaoyansi/mymagicbox/blob/master/mystring/src/mystring.h
https://github.com/yaoyansi/mymagicbox/blob/master/mystring/src/mystring.cpp
时间: 2024-10-06 20:47:29