---
title: "Operator Overloading in C++"  
description: "In this blog, I’m explaining about Operator Overloading in C++    What is operator overloading?1.Changing the definition of an operator so it can be a"  
author: "priyanka kushwaha"  
published: 2015-02-05  
updated: 2015-02-05  
canonical: https://www.mindstick.com/blog/757/operator-overloading-in-c-plus-plus  
category: ".net"  
tags: ["visual c++"]  
reading_time: 1 minute  

---

# Operator Overloading in C++

In this [blog](https://www.mindstick.com/articles/12705/myths-and-misconception-about-blog), I’m explaining about [Operator](https://www.mindstick.com/blog/144/union-intersection-and-except-operator-in-sql-server) Overloading in [C++](https://www.mindstick.com/blog/745/array-in-c-plus-plus)\

##### \
What is operator overloading?

1. Changing the [definition](https://yourviews.mindstick.com/view/70598/false-furore-over-the-leadership-definition-statement-of-army-chief-bipin-rawat) of an operator so it can be applied on the [objects](https://www.mindstick.com/forum/145447/what-are-objects) of a [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) is called operator overloading.

2. To overload an operator, we need to write a [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) for the operator we are overloading.

3. Overloading is allowed only if at [least](https://yourviews.mindstick.com/story/1471/5-autobiographies-you-should-read-at-least-once) one operand is a class instrance ([e.g](https://www.mindstick.com/forum/157370/how-to-swap-neighbor-characters-in-string-e-g-string-demo-would-be-edom) you cannot overload an operator to take two integers as operand.)

##### Example:

```
// OperatorOverloading.cpp : main project file. #include "stdafx.h"#include<iostream>using namespace std;using namespace System;class  Operatoion{            double firstNumber,SecNumber;public:            void getVal(double fn,double sn)            {                        firstNumber=fn;                        SecNumber=sn;            }            void distplay()            {                        cout<<"\n First Number is ";cout<<firstNumber;                        cout<<"\n Second Number is";cout<<SecNumber;            }            Operatoion operator +(Operatoion number)            {                        Operatoion objOper;                        objOper.firstNumber=firstNumber+number.firstNumber;                        objOper.SecNumber=SecNumber+number.SecNumber;                        return objOper;            }            void operator ++()            {                        firstNumber++;                        SecNumber++;            }public:             Operatoion();            ~ Operatoion(); private: };  Operatoion:: Operatoion(){}  Operatoion::~ Operatoion(){} int main(array<System::String ^> ^args){            Operatoion objFirst,objSecond,objResult;            objFirst.getVal(10,20);            objSecond.getVal(30,40);            objResult=objFirst+objResult;            objResult=objFirst+objSecond;            objResult.distplay();            objResult++;            objResult.distplay();            objFirst++;            objFirst.distplay();            Console::ReadKey(0);    return 0;} 
```

---

Original Source: https://www.mindstick.com/blog/757/operator-overloading-in-c-plus-plus

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
