Is it reasonable to do something like this?
Note: this is a Minimal Working Example
class A {
public:
int getX() { return x; }
protected:
int x;
virtual void setX(int newX) = 0;
};
// Children can modify X
class Can_Modify_X : public A {
protected:
void setX(int newX) { x = newX; }
private:
using A::x;
};
// Children can't modify X
class Can_Not_Modify_X : public A {
private:
void setX(int newX) { }
using A::x;
};
I'm aware that I can't simply hide a function because that would violate the Liskov Principle, but doing a private
inheritance and specify again all the public methods seems really redundant.
The two classes must have a common parent (even if it is directly one of them), and must not be able to modify x
directly.
BONUS: can somebody point me to somewhere defining the exact behaviour of using
in this cases? I tried googling it, but with very little success.