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:
- Only existing operators can be overloaded. New operators cannot be created.
- The overloaded operator must have at least one operand that is of a user-defined type.
- The basic meaning of an operator cannot change. i.e., we cannot redefine the plus (+) operator to subtract one value from another.
- The overloaded operators follow the syntax rules of the original operators.
- The following are some operators that cannot be overloaded:
Size of operator- . Membership operator
- * Pointer to member operator
- :: Scope resolution operator
- ?: Conditional operator
- 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
- Unary operators, overloaded by means of a member function, take no explicit arguments and return no explicit values.
- Unary operators, overloaded by means of a friend function, take one reference argument.
shaalaa.com
Is there an error in this question or solution?
2022-2023 (March) Official
