<<Exceptional C++>> notes

时间:2014-10-09 14:12:03   收藏:0   阅读:207

 

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

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!