0% found this document useful (0 votes)
5 views

Operator Overloading in c (1)

Operator overloading in C++ allows users to redefine the meaning of existing operators for user-defined data types, enabling operations similar to those on built-in types. Certain operators, such as the scope operator and sizeof, cannot be overloaded. The syntax and rules for operator overloading specify how to implement these functions and the conditions under which they can be used.

Uploaded by

Mohit Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Operator Overloading in c (1)

Operator overloading in C++ allows users to redefine the meaning of existing operators for user-defined data types, enabling operations similar to those on built-in types. Certain operators, such as the scope operator and sizeof, cannot be overloaded. The syntax and rules for operator overloading specify how to implement these functions and the conditions under which they can be used.

Uploaded by

Mohit Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 3

OPERATOR OVERLOADING IN C++

C++ Operators Overloading


Operator overloading is a compile-time polymorphism in which the operator is overloaded to provide the
special meaning to the user-defined data type.
Operator overloading is used to overload or redefines most of the operators available in C++.
It is used to perform the operation on the user-defined data type.
For example, C++ provides the ability to add the variables of the user-defined data type that is applied to the
built-in data types.

The advantage of Operators overloading is to perform different operations on the same operand.
Operator that cannot be overloaded are as follows:

Scope operator (::)


Sizeof
member selector(.)
member pointer selector(*)
ternary operator(?:)
Syntax of Operator Overloading
return_type class_name : : operator op(argument_list)
{
// body of the function.
}
Where the return type is the type of value returned by the function.

class_name is the name of the class.

operator op is an operator function where op is the operator being overloaded, and the
operator is the keyword.
Rules for Operator Overloading
• Existing operators can only be overloaded, but the new operators cannot be
overloaded.
• The overloaded operator contains atleast one operand of the user-defined data
type.
• We cannot use friend function to overload certain operators. However, the
member function can be used to overload those operators.
• When unary operators are overloaded through a member function take no explicit
arguments, but, if they are overloaded by a friend function, takes one argument.
• When binary operators are overloaded through a member function takes one
explicit argument, and if they are overloaded through a friend function takes two
explicit arguments.

You might also like