The three class member access specifiers have the following effect:
access specifiers | effect |
public class members | can be accessed by any function, file or class. |
private class members | can be accessed only by member functions and friends of the class in which the member is declared. |
protected class members | can be accessed only by member functions and friends of the class in which they are declared and by member functions and friends of classes derived with public or protected access from the class in which the protected members are declared . The access specifier protected can be used for nonbase class members, but it is equivalent to private unless it is used in a base class member declaration or in a base list. |
The default access for an individual class member depends on the
class key used in the class declaration. Members of classes
declared with the keyword class are private by default. Members
of classes declared with the keyword struct or union are public
by default. T he access specifier protected is meaningful only in
the context of derivation. You can control the access to
inherited members (that is, base class members) by including
access specifiers in the base list of the derived class
declaration . You can also restore the access to an inherited
member from a derived class by using an access declaration.
Member lists can include access specifiers as labels. Members
declared after these labels have access as specified by the label
they follow. An access specifier determines the access for
members until another access specifier is used or until the end
of the class declaration. You can use any number of access
specifiers in any order.
Access Declarations
Inherited Member Access
Class Member Lists
Member Access
Classes and Access Control