转换函数
class Fraction{
public:
Fraction(int num, int den = 1) : m_numerator(num), m_denominator(den) { }
operator double( ) const{ //转换函数
return (double) (m_numberator / m_denominator);
}
private:
int m_numerator; //分子
int m_denominator; //分母
}
Fraction f(3, 5);
double d = 4 + f; //调用operator double( )将f转换为double类型