Tuesday, 31 March 2015

Program for ++ unary operator Overloading

Sample Program

#include <iostream.h>

Class index
{
int value;
public:
index()
{
value =0;
}
int getindex()
{
return value;
}
void operator++()
{
value = value + 1;
}
};

void main()
{
index idx1, idx2;
cout<<”Index – 1”<<idx1.getindex();
cout<<”Index – 2”<<idx2.getindex();
++idx1;
idx2++;
cout<<idx1.getindex();
cout<<idx2.getindex();
}

No comments:

Post a Comment