#include <iostream>
using namespace std;
class Increment
{
int a;
public:
Increment()
{
a=0;
}
Increment(int x)
{
a=x;
}
friend operator++(Increment &I,int); //Use & while using Friend Function
friend operator++(Increment &I);
void print();
};
operator++(Increment &I,int)
{
I.a++;
}
operator++(Increment &I)
{
++I.a;
}
void Increment::print()
{
cout << endl << "a=" << a << endl ;
}
int main()
{
Increment I1;
I1.print();
I1++;
I1.print();
Increment I2(100);
I2.print();
++I2;
I2.print();
return 0;
}
C and C++ programs, games, softwares. Easy programming guide. Learn to code and enjoy coding in CoderNepal
Home » Unary (++) Operator Overloading using Friend Function
Unary (++) Operator Overloading using Friend Function
This is the solution that increases an integer value by 1 by overloaded operator using Friend Function (T.U. 2072)
Subscribe to:
Comments (Atom)
No comments:
Post a Comment