Tuesday, 31 March 2015

Overloading ++ and - - Operators

Sample Program

#include <iostream.h>
class inc
{
int val;
public:
inc(void)
{
val = 1;
}
void operator++(void)
{
val = val + 1;
}
void display(void)
{
cout<<val;
}
};
void main()
{
inc A;
A.display();
A++;
A.display();
++A;
A.display();
}

No comments:

Post a Comment