I am writing a function void func(K const& val)
, which part of a template class.
Assume I define a class object as foo<unsigned short int> f;
and then I call func as f.func(999999);
What happens is the value 999999
gets converted to some other value as it itself is out of range. How do I prevent this from happening? Is there a compiler flag or some other way in code where I can prevent this?
Checking
if(val > std::numeric_limits<K>::max())
inside the func
does not help, as the value is already converted when it is getting passed and into something that is inside the numeric limit.
For example, 999998989898988989999 gets converted to 11823
How do I pass values greater than std::numeric_limits::max() to a function?
P.S. I am compiling using gcc (with -std=c++11)