| <<< Rational number approximation | Index | Unary member operator syntax >>> |
// rational.h
class Rational {
private:
int m_n;
int m_d;
public:
// Member binary operator
bool operator==( Rational const& other) const;
};
// rational.cpp
bool Rational::operator==( Rational const& other ) const
{
// This way, 1/2 == 2/4 (should it?)
return ( ( m_n * other.m_d ) == ( m_d * other.m_n ) );
}
| <<< Rational number approximation | Index | Unary member operator syntax >>> |