druca
February 27th, 2010, 09:34 PM
Hi all!
I was wondering about some standard practice c++ stuff. If I make a class Fraction and operations like plus and minus etc, is it standard to return a new stack based object or modify *this to return the new value?
returning new stack based object
Fraction Fraction::operator+( const Fraction& t ) {
Fraction A ;
A.denominator = denominator * t.denominator ;
A.numerator = ( ( A.denominator / denominator ) * numerator ) +
( ( A.denominator / t.denominator ) * t.numerator ) ;
if( equal_rational( A , reduced( A ) ) == FALSE ) return ( A );
return A ;
}
It just gave me an undefined reference to its destructor...so does that mean I cannot do the above? I have done something similar in C
I was wondering about some standard practice c++ stuff. If I make a class Fraction and operations like plus and minus etc, is it standard to return a new stack based object or modify *this to return the new value?
returning new stack based object
Fraction Fraction::operator+( const Fraction& t ) {
Fraction A ;
A.denominator = denominator * t.denominator ;
A.numerator = ( ( A.denominator / denominator ) * numerator ) +
( ( A.denominator / t.denominator ) * t.numerator ) ;
if( equal_rational( A , reduced( A ) ) == FALSE ) return ( A );
return A ;
}
It just gave me an undefined reference to its destructor...so does that mean I cannot do the above? I have done something similar in C