首页 > 代码库 > <<Exceptional C++>> notes
<<Exceptional C++>> notes
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
<<Exceptional C++>> notes
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。