旧:如何通过 CRTP 基类覆盖虚函数?
struct I { virtual void foo() = 0; };
template<class D>
struct B { void foo() { } }; // provides implementation of foo in D
struct D : I, B<D> { }; // D has an implementation of foo that should override I
int main() { D d; }
Error: unimplemented pure virtual method 'foo' in 'D'
更简单:如何在不以派生类型重新实现虚函数的情况下覆盖虚函数?(我猜这个问题违背了虚函数的定义)。
struct I { virtual void foo() = 0; };
struct B { void foo() { } };
struct D : B, I { };
int main() { D d; }