Exercise: Access Methods for Members¶
Description¶
In exercise Exercise: Simple Method (Users Age By n Years), you had to modify
class User
: you removed the const
specifier from the age
member. age
is still public
, which gives everybody permission
to write to age
- not only class methods.
Introduce a private
section, and put all (not just age
) into
that section. This will break all code that accesses members
directly.
Fix that: introduce access methods for the members.