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

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -