C++ Programming Code Examples C++ > Beginners Lab Assignments Code Examples Prefix Increment ++ operator overloading with return type Prefix Increment ++ operator overloading with return type In this example, you'll learn to overload increment ++ and decrement -- operators in C++. In this tutorial, increment ++ and decrements -- operator are overloaded in best possible way, i.e., increase the value of a data member by 1 if ++ operator operates on an object and decrease value of data member by 1 if -- operator is used. This program is similar to the one above. The only difference is that, the return type of operator function is Check in this case which allows to use both codes ++obj; obj1 = ++obj;. It is because, temp returned from operator function is stored in object obj. Since, the return type of operator function is Check, you can also assign the value of obj to another object. Notice that, = (assignment operator) does not need to be overloaded because this operator is already overloaded in C++ library. #include <iostream> using namespace std; class Check { private: int i; public: Check(): i(0) { } // Return type is Check Check operator ++() { Check temp; ++i; temp.i = i; return temp; } void Display() { cout << "i = " << i << endl; } }; int main() { Check obj, obj1; obj.Display(); obj1.Display(); obj1 = ++obj; obj.Display(); obj1.Display(); return 0; }