हिंदी

Write any eight rules for operator overloading. - Computer Science 1

Advertisements
Advertisements

प्रश्न

Write any eight rules for operator overloading.

विस्तार में उत्तर
Advertisements

उत्तर

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
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?

APPEARS IN

Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×