You have to cast the zero to void
, like
condition ? expression : (void) 0;
The reason is that both the setSvc
and setObj
are declared as returning void
(as seen in the error messages). This means the result of the expression where you call them is nothing. But the other "false" expression is an expression with a value. So the ternary expression have one branch that doesn't return a value and one branch that does return a value, which is not allowed. Casting the "false" expression to void
makes both branches the same.