As we know we must perpend typename before using a Type Member of a Template Type Parameter because without it the compiler doesn't know whether we are accessing a Type member or using a static data member because the fact that the definition of the class template is not yet present (instantiation)
template <typename T>
void foo()
{
T::type x{}; // error: need a typename
typename T::type y{}; // ok
}
Until here it is OK but what about this problem I've discovered:
template <typename C_>
C_::value_type get_sum(C_ const& c) // no need to typename?!
{
C_::value_type sum0{}; // errorL: need to typename keyword
typename C_::value_type sum{};
for(auto const& i : c)
sum += i;
return sum;
}
As you can see inside the function template body the compiler complains about missing the keyword typename but using it as a return type it doesn't complain? can someone explain why?