写个c++小例子

class Rational{
public:
    const Rational operator*( const Rational& rhs);
    Rational(int num);
private:
    int a;
};

Rational::Rational(int num) :a(num)
{
}

const Rational Rational::operator*(const Rational& rhs)
{
    return Rational(this->a * rhs.a);
}

int main()
{
    Rational a(2);
    Rational b(3);
    Rational c = a * b;
    return 0;
}

 

posted @ 2016-10-11 23:58  zzyoucan  阅读(154)  评论(0编辑  收藏  举报