If I have a class that holds a protected member that derived classes will inherit:
class Base1
{
protected:
int baseMember_;
};
class Base2 : public Base1
{
public:
void printBaseMember
{
std::cout << baseMember_ << std::endl;
}
};
How can I make sure that baseMember_ will be inaccessable in classes that derive from Base2?
The obvious solution would be to simply make the inheritance private:
class Base2 : private Base1,
but this doesn't work in my case. The reason is that private inheritance removes the is-a relationship between Base2 and Base1, which I need because I need to assign objects of typeBase1* to type Base2* in several places in my code.
Is there a way to make sure that derived classes will not have access to a protected member, while still using public inheritance?