I am trying to compile some code, in one of my headers I have the following function in the global namespace:
template <class T>
inline
T
to_type<T> (const std::string& string)
{
std::stringstream ss(string);
T value;
ss >> value;
return value;
}
Yet somehow, this throws the g++ error expected initializer before '<' token
(I changed one of the quotes to solve a conflict with the SO formatting)
I don't understand this error. Why is to_type
not a valid initializer? This is the first time this symbol has been used. How do I fix this snippet?
The correct syntax is
template <class T>
inline
T
to_type(const std::string& string)
{
std::stringstream ss(string);
T value;
ss >> value;
return value;
}
(note no <T>
after to_type
).
<>
are only put after the name of the function (or class) being declared when declaring a specialization, not when declaring the base template.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With