COMP 2404 Lecture Notes - Lecture 4: Increment And Decrement Operators, Video Lesson

45 views2 pages

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents