Thursday, October 02, 2008

Why access specifiers?

  • Without access specifiers, the client programmer can do anything with that class and there is no way to enforce rules
  • Library designers can change internal workings of the class without worrying about how it will affect the client programmer.

C++ uses three explicit keywords to set the boundaries in a class: public, private, and protected.

public means the following definitions are available to everyone. private means that no one can access those definitions except you, the creator of the type, inside member functions of that type. protected acts just like private, with the exception that an inheriting class has access to protected members, but not private members.

No comments: