C++ program for overloading the unary operator ++.

by Nideesh C on April 14, 2011 · 0 comments

in C++




#include<iostream.h>
#include<conio.h>
class counter
{
int count;
public:
counter()
{
	count=0;
}
int get_count()
{
return count;
}
void operator++()
{
count++;
}
};
 
void main()
{
counter c1,c2;
cout<<"\nC1 ="<<c1.get_count();
cout<<"\nC2 ="<<c2.get_count();
 
c1++; 		//Using overloaded ++ operator.
c2++;
++c2;
cout<<"\nC1 ="<<c1.get_count();
cout<<"\nC2 ="<<c2.get_count();
getch();
}

OUT PUT:
 C1=0  C2=O
 C1=1	C2=2



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C++ program – Perform arithmetic operations of two complex numbers using operator overloading
  2. C++ program – Perform complex arithmetic using operator overloading
  3. C++ program – multiply two numbers without using multiplication operator
  4. C++ program to implement Heap sort Algorithm
  5. C++ program to implement Selection sort using class

Leave a Comment

Previous post:

Next post: