Original Post
OK, I've been ignoring this problem for such a long time I got afraid C++ would be grandpas' language by the time I dare to find the solution. What is the point of access specification if they all loose their effect on inheritance? Here is some code to clarify my point:
class Base {
public:
int GetX() { return x };
protected:
int x;
};
class Derived: public Base {
// x is public here, not good
};
class Derived2: protected Base {
// GetX() is protected here, not good again
};
There are circumstances, one may want to restore one or more inherited members to their original access specification. Herbert Schildt in his book, C++ The Complete Reference, states that there are basically two approaches to this problem: 1) The now deprecated base-class::member method, 2) The 'using' keyword And as it turns out, I really can't help myself to like any of these. I really don't like to keep an accumulated list of all redeclared class members and add them to each new inherited class on each level of my inheritance hierarchy. I wish there was some way to keep the access specification on inheritance, something that should have been supported by the language in my opinion, but is not. Isn't this a sensible and logical expectation? Also I read access redeclaration can cause shadowing problems, so now I'm thinking maybe my design is flawed after all and I shouldn't be so harsh on enforcing encapsulation. I'm so lost here. I would greatly appreciate your helps and ideas. Thank you.