English

Write any eight rules for operator overloading.

Advertisements
Advertisements

Questions

Write any eight rules for operator overloading.

State any eight rules for operator overloading.

Very Long Answer
Advertisements

Solution

Eight rules for operator overloading are as follows:

  1. Only existing operators can be overloaded. New operators cannot be created.
  2. The overloaded operator must have at least one operand that is of a user-defined type.
  3. The basic meaning of an operator cannot change. i.e., we cannot redefine the plus (+) operator to subtract one value from another.
  4. The overloaded operators follow the syntax rules of the original operators.
  5. The following are some operators that cannot be overloaded:
    Size of operator
    • . Membership operator
    • * Pointer to member operator
    • :: Scope resolution operator
    • ?: Conditional operator
  6. Following certain operators cannot be overloaded using friend functions, but member functions can be used to overload them:
    • = Assignment operator
    • () Function call operator
    • [] Subscripting operator
    • → Class member access operator
  7. Unary operators, overloaded by means of a member function, take no explicit arguments and return no explicit values.
  8. Unary operators, overloaded by means of a friend function, take one reference argument.
shaalaa.com
  Is there an error in this question or solution?
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×