Operator Overloading in C++ – Pedagogy Zone

The operator overloading feature of C++ is one of the methods of realizing polymorphism. C++ has the ability to provide the operators with a special meaning to an operator is known as operator overloading.

We can overload all the C++ operators except the following:

  • Size resolution operator (::)
  • Scope of operator (size of)
  • Conditional operator (?:)
  • Class member access operator (., .*, →*)
  • Pointer to member declarator (::*)

Defining Operator Overloading

The general format of operator overloading is as follows:

Operator Overloading in C++

{
body of operator function;
}
eg : int operator + ();
void operator – ()

The process of operator overloading involves the following steps:

  1. Declare a class (that define the data type) whose objects are to be manipulated using operators.
  2. Declare the operator function, in the public part of the class. It can be either a normal member function or a friend function.
  3. Define the operator function either within the body of a class or outside the body of the class.

Syntax for invoking the overloaded unary operator function is as follows:

Object operator
Operator object

eg : S++;
++S;

Syntax for invoking the overloaded binary operator function is as follows:

eg : S1 + S2  invokes the overloaded member function + of the S1 object’s class by passing S2 as the argument.

Read More Topics
Const member function in C++
Default copy constructor in C++
The HyperText Transfer Protocol
Five layer reference model in computer network
Unique nature of web apps

About the author

Santhakumar Raja

Hi, This blog is dedicated to students to stay update in the education industry. Motivates students to become better readers and writers.

View all posts

Leave a Reply