Operator Overloading Example in C++


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.

Example Program:

Here is the simple program using operator overloading in C++.

Source Code

using namespace std;

class Complex
public :
    int real;
    int img;

    Complex operator +(Complex c)
        Complex temp;
        return temp;


int main()
    Complex c1,c2,c3;
    cout<<"\nReal : "<<c3.real;
    cout<<"\nImg : "<<c3.img;
    return 0;
To download raw file Click Here


Real : 15
Img : 8

Basic Programs

Flow Control

IF Statement Examples

Switch Case

Goto Statement

Break and Continue

While Loop

Do While Loop

For Loop

Friend Function in C++

String Examples

Array Examples

Structure Examples

Structure & Pointer Examples

Structure & Functions Examples

Enumeration Examples

Template Examples


Inheritance Examples

Hierarchical Inheritance

Hybrid Inheritance

Multilevel Inheritance

Multiple Inheritance

Single Level Inheritance

Class and Objects

Constructor Example

Destructor Example

Operator Overloading Example

Operator and Function Example

List of Programs

Pointer Examples

Memory Management Examples

Pointers and Arrays

Virtual Function Examples

Learn All in Tamil © Designed & Developed By Tutor Joes