L18overloading

L18overloading - Operator overloading q Class time Class...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Operator overloading
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Class date represents the date of year class Date { public: ??? private: int month; int day; int year; }; what would you write if you need to compare two dates for equality? Use accessor functions: return( date1.getday() == date2.getday() ); } looks like accessors are not helping Class time
Background image of page 2
Can we write something like this? return( date1.day == date2.day ); } we cannot because year , month and day are private variables of objects and equal is not a class member. Can we make it a class member? We cannot: if such function is called as follows date1.equal(date2) then it can access the private vars of date1 but not date2 what shall we do? Class time (cont.)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

L18overloading - Operator overloading q Class time Class...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online