是否有人知道C++中的语言特性或技术,以防止子类过度使用父类中的特定方法?
class Base {
public:
bool someGuaranteedResult() { return true; }
};
class Child : public Base {
public:
bool someGuaranteedResult() { return false; /* Haha I broke things! */ }
};
Run Code Online (Sandbox Code Playgroud)
尽管它不是虚拟的,但仍然允许这样做(至少在我正在使用的Metrowerks编译器中),所有你得到的是关于隐藏非虚拟继承函数X的编译时警告.