Chapter 14
Protecting Members: Do Not Disturb
In This Chapter
Declaring members protected
Accessing protected members from within the class
Accessing protected members from outside the class
Chapter 12 introduces the concept of the class. That chapter describes the public keyword as though it were part of the class declaration — just something you do. In this chapter, you find out about an alternative to public.
Protecting Members
The members of a class can be marked protected, which makes them inaccessible outside the class. The alternative is to make the members public. Public members are accessible to all.
Why you need protected members
To understand the role of protected, think about the goals of object-oriented programming:
- To protect the ...
Get C++ For Dummies, 7th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.