lecture 31: Rules for overloading operators | C++

Опубликовано: 16 Июнь 2026
на канале: BCA Lectures
12
0

OPERATOR OVERLOADING 31-05- 2024 C++

C++ tries to make the user defined datatypes ________ in the same way as the built-in datatypes. C++ enables us to add 2 different variable types with the same types used in the _____datatypes. C++ has the ability to provide the operators with a special name for a datatype. The mechanism of such special menuto an operator is known as _____

To define an additonal task, to an operator we must specify what it means in relation to the class to which the operator is applied. This is done with the help of a special function called "operator function". Operator functions must be either member function (non-static) or friend function.A friend function will have only one argument Unary operators. and two arguments for binary operators, while a member function has no arguments for uniary operators and only 1 arguments for binary operators.

Rules for Overloading operators:
1. Only existing operators can be overloaded. new opeartors cannot be created.
2. The overloaded operator must have atleast 1 operant that is of user defined type.
3. We cannot change basic meaning of an operator.
4. Overloaded operators must follow the syntax rules of the orignal operators. That cannot be overridden.


There are some operators that cannot be overloaded --

________________________________________________________________________________
operator Name
________________________________________________________________________________
sizeof(); size of operator
. Membership operator
.* pointer to member operator
:: scope resolution operator
?: Conditional operator
________________________________________________________________________________