COMP 2404 Lecture Notes - Lecture 3: Operator Overloading, Video Lesson

99 views3 pages

Document Summary

When over loaded as a global function, takes one parameter (object or object reference) When overloaded as member functions it takes no parameters and the function cannot be static e. g. !operator in class example. When overloaded as global function it takes to parameters of which one must be an object or reference to the object operated on. e. g. t1 + t2 would be translated as operator+(t1,t2) So now let"s take an example from the time class discussed before. Let"s say we want to add some time to the lunch time. in main we write. Time lunch(12); lunch += 80; what we mean here is that we want to add 80 seconds to the lunch time, we need to over load the += to operator . We need to overload this explicitly because the left and right hand side are not same and are not primitive data types so we don t get an implicit overload.

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