etc can not can be overloaded 2162011 5 similar

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: rator∆( a, b) However, However, some operators like ::, ., etc. can not ::, can be overloaded. 2/16/2011 5 Similar Similar for >> and other operators, one more example: overload “great than” > for Time In In .h file: declare it, bool operator>(const Time & t1, operator>(const const Time & t2); In .cpp In .cpp file: define it, bool operator>(const Time &t1, operator>(const const Time &t2) {return t1.getMilTime() > t2.getMilTime();} In In main.cpp file: use it, Time mealTime, classTime; mealTime, classTime; …… if (classTime > mealTime) (classTime mealTime) { ……… } 2/16/2011 6 2 Examples of Operator Overloading (External) Note Note the overloaded I/O operators << and >> in the expanded Time class >> Fig 4.7 on page 172-176 on 172Δ Note Note these operators overloading are defined as defined external external functions (internal method later). later). 2/16/2011 7 Internal Method: Syntax (compare with external way) Suppose Supp...
View Full Document

Ask a homework question - tutors are online