According to another answer, you can use the final keyword in C ++ 11 (such an object is similar to the Java final keyword).
For C ++ 03 code, you can use the CRTP mechanism (if you can change the definition of Interface )
template<typename Derived> class Interface { public: void foo() // not 'virtual' { static_cast<Derived*>(this)->foo(); } } class MyClass : public Interface<MyClass> { public: virtual void bar() = 0; private: void foo() { //Some private work and checks. bar(); }; }
So, now you remove virtual ness foo() , and the binding will happen at compile time. Remember that CRTP comes with its own restriction, so whether you use it or not is up to you.
source share