Can I multiply an int with a boolean in C++? -
i have widget in gui displays chart(s). if have more 1 chart there legend shown in rectangle on gui.
i have qstringlist (legendtext)
holds text of legend. if there no legend required, legendtext
empty. if there legend, legendtext
hold text.
for finding height of rectangle around legend following:
int height = 10; qstringlist legendtext; ... height = height * (legendtext->size() > 0); ...
is idea/ style multiply int
boolean
? run problems that?
this technically fine, if bit unclear.
the bool
promoted int
, result well-defined. however, looking @ code don't instantly semantics trying achieve.
i write like:
height = legendtext->isempty() ? 0 : height;
this makes intent far clearer.
Comments
Post a Comment