Posted by Amit Nithian on May 04, 2001 at 00:20:00:
In Reply to: Implicit Conversions posted by Michael Young on May 03, 2001 at 23:26:51:
: From the notes and class lectures, I know that if there is a constructor that takes one parameter, then that is used to convert from that type.
: So, if class Rational contained:
: Rational(int Top, int Bottom=1);
: Rational operator+(const Rational& RHS);
: Then you could write:
: Rational A, B(1);
: and it would compile. 3 would be coverted to a Rational and added to B. However, what if you were to write:
: Would the compiler know to convert 3 to a Rational? If not, how can we make it, aside from explicitly saying it? 'cause, it seems natural to write it that way.
: Michael Young
It would seem to me that there would have to be a + operator defined that takes a left hand parameter of integer. It is possible that there is some default constructor (with default arguments) that handles this, which to me throws things off.
- Amit Nithian
Post a Followup