How does protected inheritance work. Here child_protected inherits Base as protected. Now the public member of Base is protected for child_protected class.
So when I create an object of child_inheritance should public_member be accessible by . operator??
class Base {
//Public members accessible by everyone
public:
int public_member;
//Protected members accessible only inside class by class in which it is defined and its child
protected:
int protected_member;
//Private members are accessible only inside class in which it is defined and by friend members
private:
int private_member;
};
//Everything child_protected inherits from base is now protected i.e. public member of Base is protected here
class child_protected : protected Base {
public:
void print() {
//Protected members are accessible inside class
cout << this->protected_member<<endl;
cout << this->public_member<<endl;
}
};
When you use protected inheritance:
all public members from Base class are protected in child_protected
all protected members are still protected
all privete members are still private