phil at mobleybros dot com wrote:
> I am working on a Rational (fraction) class, and I have the operators
> working fine for Rational -> Rational functions, but I want to be able
> to also work with Integers and Doubles.
>
> What would be better (and/or easier)?
>
> Overload Operator_Add and Operator_AddRight (and all other math
> operators) or should I overload the Operator_Convert?
These are different tools for different problems. If you want support for
the math operators, you need to implement the math operator methods; if you
want the user to be able to assign an integer or double value to a variable
declared as Rational (or vice versa), you need to implement the conversion
operator method.
> Given this formula:
>
> ratB = ratA + 3
>
> Do I have to have an Operator_Add(Integer) or will
> Operator_Convert(Integer) work? What about:
>
> ratB = 3 + ratA
Operator_Convert does not apply. In the former case, you'd need Operator_Add
with an integer parameter; in the latter case, you'd need Operator_AddRight
with an integer parameter.
Mars Saxman
REAL Software
--
REAL World 2005 - The REALbasic User Conference
March 23rd - 25th, 2005, Austin, Texas
<http://www.realsoftware.com/realworld>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
|