comparison operation

Hi,

In c++, I can do this:

     int n = 5;
     n == 0 ? ok() : notok();

This doesn't seem to be possible, keep getting compilation errors about the n == 0 part, can't convert integer to boolean?

Is there some way to do that?

Thanks
DJ_AM_JuiceboxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cmalakarCommented:
ok() or notok() should return a value...

like..

var = (n==0) ? ok() : notok();
0
DJ_AM_JuiceboxAuthor Commented:
musn't both return a value then? I mean what would the effect of var = (void SomeFunc()) be?

Also, why do they HAVE to return a value? What if the two functions are just meant to return void?

Thanks
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

cmalakarCommented:
>> what would the effect of var = (void SomeFunc()) be?

You cannot use function returning void in ?: operator..

You must use function returning some value...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cmalakarCommented:
As every operator (+, -) is expected to return a value..

?: (Conditional operator) is also expected to return a value
0
cmalakarCommented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.