Overloading Increment and Decrement Operators in Prefix form OOP using friend function and member function
#include<bits/stdc++.h>
using namespace std;
class pre
{
int val;
public :
pre()
{
val=0;
}
pre(int v)
{
val=v;
}
void display()
{
cout<<val<<endl;
}
void operator++()
{
val=val+1;
}
friend pre operator--(pre &);
};
pre operator--(pre &v)
{
v.val-=1;
}
int main()
{
pre a(10);
a.display();
++a;
a.display();
--a;
a.display();
return 0;
}
0 Comments