Hello to all !
i am encoding a class about rational numbers, holding the numerator and a denominator and all operators like are overloaded for it..it works all so fine ecxept for one wierd point:
my cast-to-double operator is called at the times it is not called at all..for example i debugged the program and noticed that it is called in the copy constructor, while i never used the function in it..i donno what i'm doing wrong? what is it that puts the compiler into the mistake of calling this function at times it is not called?
class Rational
{
private:
int numerator;
int denominator;
public:
Rational(Rational &r);
Rational(int n=1,int d=1);
Rational operator+(Rational num);
Rational operator-(Rational num);
Rational operator*(Rational num);
Rational operator/(Rational num);
Rational& operator++();
Rational operator++(int a);
Rational& operator--();
Rational operator--(int a);
int getnumerator();
int getdenominator();
void setnumerator(int n);
void setdenominator(int d);
[B]operator double() const
{
return numerator/(double)denominator;
}[/B]
operator string();
}
for example it is called in the line bolded below :
Rational& Rational::operator --()
{
Rational one(-1,1);
[B]Rational result(*this+one);[/B]
this->setnumerator(result.getnumerator());
this->setdenominator(result.getdenominator());
[B]return *this;[/B]
}
can any one figure out why ? :-?
tanx in advance