Aim: Write a
program to demonstrate the overloading of increment and decrement operator.
Ans:
#include<iostream.h>
#include<conio.h>
class A
{
int x;
public:
A()
{
x=40;
}
void operator ++()
{
x++;
}
void output()
{
cout<<x<<"\n";
}
};
void main()
{
clrscr();
cout<<"Initial value of x=40\n\n";
cout<<"New value of x after using
operator overloading is:\n";
A o1,o2;
o1++;
o2++;
o2++;
o1.output();
o2.output();
getch();
}
No comments:
Post a Comment