struct A
{
template <class U>
void f(U)
{
}
};
template <class T>
void f(T t)
{
A a;
a.template f<int>(t);
a.template f<>(t);
a.f<int>(t);
a.f<>(t);
a.f(t);
}
At least under MSVC2010 the above code compile fine.
Among all the manners to call A.f is there any preferentials way to do this?
Is there any differences ?
Well,
ahas typeA, which is not a dependent type in this context. So thetemplatekeyword is not needed and only serves to obfuscate the code — don’t use it.The version that invokes a template without supplying any arguments, again does nothing to change behavior and only makes the code less readable — don’t use it either.
Between the two remaining candidates,
a.f(t)anda.f<int>(t), use the first in most cases, and the second if the compiler fails to deduce the type.