码迷,mamicode.com
首页 > 编程语言 > 详细

<<Exceptional C++>> notes

时间:2014-10-09 14:12:03      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   for   sp   

 

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

标签:style   blog   http   color   io   os   ar   for   sp   

原文地址:http://www.cnblogs.com/yaoyansi/p/4012354.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!