Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class cObject {
- private:
- int id;
- double weight;
- public:
- cObject(int id, double w): id { id },
- weight { w } { }
- void print() {
- std::cout << "Object #" << id << " has weight " << weight << "\n";
- }
- cObject operator--() {
- return cObject(id, weight - 1.0);
- }
- cObject operator--(int) {
- cObject o(id, weight);
- weight -= 1.0;
- return o;
- }
- };
- int main() {
- cObject a(1, 8);
- cObject b(2, 2);
- a.print();
- b.print();
- (a--).print();
- (--b).print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement