This preview shows page 1. Sign up to view the full content.
Unformatted text preview: usually) all private.
Thus there are three pieces of memory called
now.hours, now.minutes and now.seconds.
now.hours now.minutes and now.seconds
Just like a struct.
struct Applied Programming But, unlike a struct, these memory locations
are private. This means that only member
functions of the class have access.
functions Applied Programming Similarly
would add one second to now.
now Thus, a call to
would set the three components of the object now
to the time 13 hours, 10 minutes and 0 seconds.
Applied Programming would output the value of now – without changing
But how do we protect this?
Applied Programming By the use of the keyword const.
const A call of the form
now.Set(a,b,c); Because the instance is not an argument we
cannot put const iin front of it, so we put const
after the function itself. is converted to
Set(now,a,b,c); So we have since the function
Set(int,int,int); void Write() const; is actually
Set(TimeType&,int,int,int); Let's look at the mecha...
View Full Document
- Spring '14