write a program to overload the postfix decrement operator
#include <iostream>
using namespace std;
class Integer {
int value;
public:
Integer(int v=0) {
value = v;
}
Integer operator--(int) {
Integer tmp = *this;
--value;
return tmp;
}
void print(ostream& os) {
os << value;
}
};
ostream& operator<<(ostream& os, Integer& i) {
i.print(os);
return os;
}
int main() {
Integer I(100);
cout << "I : " << I << endl;
cout << "I-- : " << I-- << endl;
cout << "I : " << I << endl;
return 0;
}
Comments
Leave a comment