Person::name is private to all external and non-friend functions. Therefore, Person::name can only be accessed by the members of Person. If you swap private with protected within Person, any derived classes will be able to access those members directly. To do this, you would do something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
class Person
{
// Other members...
protected:
string name;
int age;
};
class PEmployee : private Person
{
// Other members...
inline string GetName( ) const
{
returnthis->name;
}
private:
double salary;
};
Here, only PEmployee can access the protected members of Person. When PEmployee derives from Person, all of Person's members became members of PEmployee. However, since PEmployee is privately derived from Person, only the members of PEmployee can access the protected members of Person; no external functions or variables can access the protected members of Person.