I have written a template function which takes int32, bool and int16 as an input. However for bool, I am getting this warning. Any ideas, how can I resolve it.
template<class T>
void GameControl::assignValues(char *gaff, T &output)
{
output = T(atoi(gaff));
}
The function calls are as follows:
int32 intout;
assignValues("1234", intout);
bool boolout;
assignValues("1234", boolout);
can anyone tell, how to get rid of the warning?
EDIT: This worked, but not sure of the consequences. I just suppressed the warning.
#pragma warning( push )
#pragma warning( disable : 4101)
// Your function
#pragma warning( pop )
bool
? – Some programmer dudeatoi
function is usually discouraged, as it's impossible to differ between a valid input"0"
and an invalid input which results in0
being returned. I recommendstd::strtol
orstd::stoi
instead. – Some programmer dudeint23 intout = assignValues("1234");
– juanchopanzabool
it would bebool boolout = assignValues("1234") != 0;
– Some programmer dude