Operator Overloading C++ Example


Prev Tutorial Next Tutorial

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

Prev Tutorial Next Tutorial

Google Advertisements
Download Projects

Google Adsense Advertisements

Buy 3 Year Old Domain, Tutorialday.com, SeosmoTools.com @$200

Buy This Ad Space @$50 per Month, Ad Size 300X250 Contact on: hitesh.xc@gmail.com WhatsApp no. 8882538826

Yahoo Advertisements