It only works if there is a deduced template argument involved. You probably need to add a level of indirection and also disable the first method in case T
does have a suitable _Foo
. Or, as an alternative, I'll show how to lower its priority for overload resolution by using ...
vs. int
:
template <class T>
void foo_impl(const Foo* f, T*, ...) // this is general case template
{
}
// this should work only if T has static variable named _Foo with type const Foo*
template <class T>
typename std::enable_if<std::is_same<decltype(T::_Foo), const Foo*>::value>::type
foo_impl(const Foo* f, T*, int)
{
T::_Foo = f;
}
template <class T>
void foo(const Foo* f) // this is general case template
{
return foo_impl(f, (T*)nullptr, 0);
}