class Base { public: virtual void f() = 0; };
class Derived :public Base { virtual void f() override { } public: };若改為靜態多型可能會像以下這樣:
template<typename DERIVED> class Base { public: void f() { static_cast<DERIVED*>(this)->f_Imp(); } };
class Derived :public Base<Derived> { void f_Imp() { } public:
friend class Base<Derived>; };