Search code examples
c++visual-c++operator-overloadingfriend

How a write a global non member post decremented overloaded operator?


I am beginning to programming. I am stuck in this point so I hope you guys will help me.

When we write a post decrement member function the syntax for that is

     type type::operator--(int){}

But I want this to be a friend function so how can i write it?

This is for pre increment:

   friend Mystring &operator--(  Mystring &lhs);

What is the syntax for post incrementation?


Solution

  • Try like this:

    class type
    {
    // ...
        // postfix operator--
        friend type operator--(type &t, int){type t1; /* some logics */ return t1;}
    };