Re: Implicit Conversions


[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]

Posted by John Kugelman on May 04, 2001 at 04:20:17:

In Reply to: Implicit Conversions posted by Michael Young on May 03, 2001 at 23:26:51:

Make the operator global instead of a member function.

class Rational
{
  >  Rational(int Top, int Bottom = 1);
}

Rational operator + (const Rational &, const Rational &);

This way both operands will be subject to automatic promotion rules. As a general rule it's better to use this syntax whenever possible since it "behaves" better regarding argument order and unclutters a class's interface. And if at all possible, try to avoid making global operators friends of the class; most class operators don't need access to the internals of the class, which of course eliminates unnecessary dependencies on its internal representation.




Follow Ups:



Post a Followup

Name:
E-Mail:

Subject:

Comments:

Optional Link URL:
Link Title:
Optional Image URL:


[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]