0

I have checked this post but have some confusions regarding the usage rules of operator overloading.

For example, here are some usage restrictions:

void operator() ()

  • Can overload '()' operator without any parameters.
  • Must used on the'right' of the operand.
void operator+ ()
  • Can overload '+' operator without any parameters.

  • Must be on the 'left' of the operand.

void operator << (int val)
  • Must have 1 parameter. Cannot be 0 parameters or 2 parameter. Only 1 parameter.

  • Must be used on the right of the operand.

These are just few of the rules in operator overloading. I would appreciate if someone could direct me to a reference or explain the rules governing each type of these operators. Why some operators must have one parameter and why '()' must be used on the right of the operand while '+' must be used on the left of the operand.

Thank you very much.

Community
  • 1
  • 1
madu
  • 5,232
  • 14
  • 56
  • 96
  • 1
    http://www.learncpp.com/cpp-tutorial/91-introduction-to-operator-overloading/ There is a whole chapter on this website – Scott Feb 15 '15 at 05:59
  • I think you should remove "if someone could direct me to a reference or " from your post so it's kosher. – ChiefTwoPencils Feb 15 '15 at 06:01

0 Answers0