Operator Overloading C++ Example
Advertisements
Operator Overloading Program in C++
C++ Overloading (Operator and Function) C++ allows you to specify more than one definition for a function name or an operator in the same scope, which is called function overloading and operator overloading respectively.
Operator Overloading Example in C++
#include<iostream.h> #include<conio.h> class temp { private: int count; public: temp():count(10) { } void operator ++() { count=count+1; } void Display() { cout<<"Count: "<<count; } }; void main() { clrscr(); temp t; ++t; /* operator function void operator ++() is called */ t.Display(); getch(); }
Output
11
Google Advertisment