EECE 2560 Lecture Notes - Memory Management, Operator Overloading, Prime Time Access Rule
Document Summary
Return lhs. hour == rhs. hour && lhs. minute == rhs. minute; Operator overloading with global functions bool operator == (const time24 &lhs, const time24 &rhs) example of something we can do. //assignment operators, e. g. t1 = t2; if not overloaded, default memberwise assignment is performed. // but we cannot overload the assignment operator with a global function. //1 = x ; the left-hand operand must be an object. So this would compile if overloading with global functions were allowed. // instead, we must overload the assignment operator with a class member function. Operator overloading with class member functions lhs op rhs; // 1. if you"re in a time24 class, you can access private data from any time24 class, which is why we didn"t have to use rhs. gethour() or rhs. getminute() // 2. must return left-hand object type, i. e. time24 class. Can we overload the i/o operations using a class member function? cout << time1;