Answer to Question #264099 in C++ for raashi

Question #264099

Write a program in C++, which demonstrates pre-increment operator overloading.



1
Expert's answer
2021-11-10T11:27:41-0500
#include <iostream>
using namespace std;


class Counter
{
private:
	int count;
public:
	Counter(): count(0) {  }
	void operator ++() { 
		++count; 
	}
	void Display() { 
		cout << "count = " << count << endl; 
	}
};


int main()
{
	Counter counter;
	counter.Display();
	++counter; 
	counter.Display();


	int k;
	cin>>k;
	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