Have the following code:
short a = 5;
short b = 15;
short c = 25;
short d = std::min(a, b);
short e = std::min(a, b-c); // Error
The last line cannot be compiled, claiming that there's no overload of min() that matches the arguments "short, int".
What is the reason for this being the case? I understand that the result of b-c could potentially not fit in a short anymore. However that would be the same if I were using INTs and there it doesn't automatically form a LONG or anything to enforce that it fits.
As long as I am sure that the resulting number will never exceed the range of SHORT, it is safe if I use static_cast<short>(b-c)
, right?
Huge thanks!