COMP 2404 Lecture Notes - Lecture 4: Increment And Decrement Operators, Video Lesson
Document Summary
Increment and decrement both involve prefix and postfix. Both of them can be overloaded as global and member functions with different syntax. Since both increment and decrement both modify the object and do not return anything new then we know that there return type should a reference to the object that is getting incremented or decremented in order to enable cascading. They modify the object do not make or return a new one. Returns a reference to the object to enable cascading. When implemented as a member functions takes no parameters. We see some complications because when implementing the ++ operator the prototype is operator++(), we do not if this prototype relates to the post fix or prefix operator. Solution: we introduce a dummy parameter for prefix we use this prototype: time& time::operator++() implementation : Time& time::operator() return convertfromseconds( (converttoseconds() - 1)); we need a dummy parameter for post fix operator.