Operator Overloading C++ Example

Advertisements

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 Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements