Try the following:
template <typename T, typename=void> struct B : A { ... }; temlate <typename T> struct B<T, typename std::enable_if<...some condition...>::type>: A { virtual int f() const override { return 1; } };
where we have two versions of B<T> for which the condition is true ( enable_if one), for which the condition is false (by default).
If you want to use the default reimplementation of B , you could even do this:
template <typename T, typename=void> struct B : A { ... }; template <typename T> struct B<T, typename std::enable_if<...some condition...>::type>: B<T, bool> { virtual int f() const override { return 1; } };
where we inherit the βfalseβ case in the βtrueβ case. But for me this is a bit dirty - I would rather instead hack into the overall implementation in third place ( B_impl ). (This also allows you to statically state that the second argument is void in the first case B ).
source share