Answer to Question #326365 in C++ for raji

Question #326365

write a program to overload the postfix decrement operator


1
Expert's answer
2022-04-10T05:24:27-0400
#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;
}

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