View Single Post
pichlo's Avatar
Posts: 6,445 | Thanked: 20,981 times | Joined on Sep 2012 @ UK
#106
You pretty much figured it out yourself. qMin returns a double, so
Code:
qMin(qMin(s.width() / 2, s.height() / 2), f)
is seen by the compiler as
Code:
qMin(double, whatever_type_f_is)
If f is float, convert it to double. The best solution would be to make it double to start with, but if that is not practical, simply cast it:
Code:
qMin(qMin(s.width() / 2, s.height() / 2), double(f))
C++ is funny like that. In C, the conversion from float to double is automatic. C++ thinks it's too cool for that.

EDIT:
In this case, C++ cannot convert automatically because qMin is a template and requires the same type for both parameters. The compiler does not know whether to convert them both to float or to double, so it gives up and throws a wobbly. I still think it should be smart enough to convert them both to the wider type, but as I say, C++ can be funny sometimes.
__________________
Русский военный корабль, иди нахуй!

Last edited by pichlo; 2021-07-07 at 11:17.
 

The Following 3 Users Say Thank You to pichlo For This Useful Post: