Overloading Increment and Decrement Operators in Postfix form





This video tutorial explains how to overload increment and decrement operators in c++ when they are using as postfix.
You are going to learn how to define operator function to overload increment and decrement operator in postfix form, how to use friend function to overload increment and decrement operators in detail with example.

source code for this tutorial

#include <iostream>

using namespace std;

class Marks{
int mark;
public:
    Marks(){
        mark = 0;
    }
    Marks(int m){
        mark = m;
    }
    void yourMarkPlease(){
        cout << "your mark is "<<mark<<endl;
    }
    Marks operator++(int){
    Marks duplicate(*this);
    mark += 1;
    return duplicate;
    }

    friend Marks operator--(Marks&,int);

};

Marks operator--(Marks &m,int){
    Marks duplicate(m);
    m.mark -= 1;
    return duplicate;
}

int main()
{

    Marks anil(68);
    anil.yourMarkPlease();

    (anil--).yourMarkPlease();
    anil.yourMarkPlease();

    return 0;
}