I know there are other questions like this but they are not very clear.
Now I feel as though this is a stupid question because I'm sure I already have the answer but let me ask anyways.
So I basically have a function that takes in a string and then based on the appropriate variable type it converts it like so:
template<class T>
void ConvertValue(std::string str, T &variable)
{
variable = static_cast<T>(str);
}
so this seems to be fine correct? But the thing is that you cannot convert a string to say an int or a float so therefore I would have to do template specialization for ints and floats and for other types it can't convert to so what I'm asking is should I have something like this:
void ConvertValue(std::string str, int &variable) { variable = atoi(str.c_str()); }
void ConvertValue(std::string str, float &variable) { ... }
void ConvertValue(std::string str, double &variable) { ... }
void ConvertValue(std::string str, std::vector<int> &variable) { ... }
..etc
or should I use template specialization? Which one would make more sense? I'm leaning towards function overloading because majority of the types are going to have their own conversion function so since they slightly differ function overloading makes logical sense to me but I don't know if I'm missing something.
Should I stick with function overloading? Or switch to template specialization?