Afficher un message
Vieux 06/12/2007, 16h00   #1
dolphin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut A question about operator overloading?

Hi All
I just read the C++FAQ . I have something confused. The question
is that :

If you provide constructive operators, they should allow promotion of
the left-hand operand (at least in the case where the class has a
single-parameter ctor that is not marked with the explicit keyword).
For example, if your class Fraction supports promotion from int to
Fraction (via the non-explicit ctor Fraction::Fraction(int)), and if
you allow x - y for two Fraction objects, you should also allow 42 -
y. In practice that simply means that your operator-() should not be a
member function of Fraction. Typically you will make it a friend, if
for no other reason than to force it into the public: part of the
class, but even if it is not a friend, it should not be a member.


Why the operator-() should not be a member function? Can someone give
a example?
  Réponse avec citation
 
Page generated in 0,04416 seconds with 9 queries