Write a program in C++, which demonstrates pre-increment operator overloading.
#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;
}
Comments
Leave a comment