Thus there are three pieces of memory called thus

This is the end of the preview. Sign up
to
access the rest of the document.

Unformatted text preview: usually) all private.
Thus there are three pieces of memory called
Thus
now.hours, now.minutes and now.seconds.
now.hours now.minutes and now.seconds
Just like a struct.
Just
struct Applied Programming But, unlike a struct, these memory locations
But,
struct these
are private. This means that only member
private This
functions of the class have access.
functions Applied Programming Similarly
now.Increment();
would add one second to now.
would
now Thus, a call to
And
now.Set(13,10,0);
now.Write();
would set the three components of the object now
would
now
to the time 13 hours, 10 minutes and 0 seconds.
Applied Programming would output the value of now – without changing
would
now without
the contents.
the
But how do we protect this?
Applied Programming By the use of the keyword const.
By
const A call of the form
now.Set(a,b,c); Because the instance is not an argument we
Because
cannot put const iin front of it, so we put const
const n
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&amp;,int,int,int); Let's look at the mecha...
View Full
Document