Answer to Question #262743 in C++ for John

Question #262743

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

(--) operator.


1
Expert's answer
2021-11-08T11:37:24-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS