Question #262743

Write a program to overload unary (++) operator and unary

(--) operator.


Expert's answer

#include <iostream>


using namespace std;


class classA {
public:
	int x, y;
	classA(int a, int b)
	{
		x = a;
		y = b;
	}
	void operator+()
	{
		x++;
		y--;
		cout << "\nx & y (Increment): " << x << ", " << y;
	}
};


int main()
{
	classA a1(5, 6);


	+a1;
	return 0;
}

LATEST TUTORIALS
APPROVED BY CLIENTS