>can you force derived classes to have foo_impl, and have an inlined function foo in the base class that calls foo_impl?
If that's all you want just write:
void foo()
{
static_cast<Derived&>(*this).foo_impl();
}
When the derived class doesn't have any method "foo_impl" (or no "foo_impl" with a suitable signature), you will get a compile-time error.No need for the static_assert, that was just because KKKKkkkk1 asked whether checking for the existence of a method at compile-time was possible.
Compile-time polymorphism is essentially duck typing: If it quacks like a duck you can treat it as one. If it doesn't quack like a duck, but you still treat it as one you get a compiler error.