随笔

class Rational
{
public:
    Rational(int numerator = 0, int denominator = 1);
    int numerator() const;
    int denominator() const;
    
private:
};

const Rational operator*(const Rational& lhs, const Rational& rhs)
{
    return Rational(lhs.numerator() * rhs.numerator(), lhs.denominator() * rhs.denominator());
}
int main()
{
    Rational oneEighth(1, 8);
    Rational oneHalf(1, 2);
    Rational result = oneHalf * oneEighth;
    result = result * oneEighth;
    result = oneHalf * 2;//让两个参数都通过隐式转换
    result = 2 * oneHalf;
    return 0;
}

 

posted @ 2017-03-21 00:23  zzyoucan  阅读(129)  评论(0编辑  收藏  举报