Restoring access of Public and protected members of Base class when derived as Private

Whenever a Base class is derived a private , the public and protected members of the base class becomes private to the derived class and become inaccessible. But its possible to  restore the access mode of such variables by using ::(scope resolution operator ) inside the derived class.
class base {
int j; // public in base
// here is access declaration
class derived:private base
base::j; // make j public again

As base is inherited as private by derived, the public member j is made a private
member of derived. However, by including
as the access declaration under derived’s public heading, j is restored to  public
Otherwise , its not possible for the derived class to access the variable j.
You can use an access declaration to restore the access mode of public and protected
members. But its not possible to modify the access status a private member function or a variable of the base class.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s