COMP 2404 Lecture Notes - Lecture 3: Operator Overloading, Video Lesson
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.