< Previous | Contents | Next >

Using Access Modifiers with Class

Members

Youve seen the access modifiers public and private used with class members before, but theres a third modifier you can use with members of a classprotected. Thats what I use with the data member of Enemy.

protected:

int m_Damage;

Members that are specified as protected are not accessible outside of the class, except in some cases of inheritance. As a refresher, here are the three levels of member access:

n public members are accessible to all code in a program.

340 Chapter 10 n Inheritance and Polymorphism: Blackjack


n protected members are accessible only in their own class and certain derived classes, depending upon the access level used in inheritance.

n private members are only accessible in their own class, which means they are not directly accessible in any derived class.