?
Solved

comparison operation

Posted on 2008-01-28
6
Medium Priority
?
165 Views
Last Modified: 2010-03-30
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
0
Comment
Question by:DJ_AM_Juicebox
  • 5
6 Comments
 
LVL 23

Expert Comment

by:cmalakar
ID: 20765218
ok() or notok() should return a value...

like..

var = (n==0) ? ok() : notok();
0
 

Author Comment

by:DJ_AM_Juicebox
ID: 20765247
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 23

Accepted Solution

by:
cmalakar earned 2000 total points
ID: 20765260
>> 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
 
LVL 23

Expert Comment

by:cmalakar
ID: 20765272
As every operator (+, -) is expected to return a value..

?: (Conditional operator) is also expected to return a value
0
 
LVL 23

Expert Comment

by:cmalakar
ID: 20765281
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month5 days, 22 hours left to enroll

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question