| <<< Common uses of operators | Index | The dual operator[] idiom >>> |
// rational.h
class Rational {
//...
public:
Rational& operator--(); // prefix (result is an lvalue!)
const Rational operator--(int); // postfix (not an lvalue)
};
// rational.cpp
Rational& Rational::operator--()
{
m_n -= m_d;
return *this;
}
const Rational Rational::operator--(int)
{
Rational temp = *this;
m_n -= m_d;
return temp;
}
| <<< Common uses of operators | Index | The dual operator[] idiom >>> |