Passing bool as an expression

I have some MT4 code I am converting to C++ and I have run into a problem with passing a bool expression to the function. The MQL function is:

bool iifBool( bool condition, bool ifTrue, bool ifFalse)
{
if( condition ) return ( ifTrue );
else return( ifFalse );
}

It compiles with a Borland compilera without error but always evaluates to ifFalse. It looks like my 'condition' parameter is not being passed in C++ as it is in MQL.

An example of how I would use it is...

Print( iifBool(a>=b, True, False) );

Any idea how I pass the expression "a>=b" to the function in C++ as I did in MQL?

Tom
True and False need not be capitalized. Just saying.

And that code should work otherwise.

-Albatross
Last edited on
I'm not sure your code is doing what you think...
You cannot defer evaluation of an expression in C++ outside of the language defined flow control constructs.

In C++, you would do something like:
1
2
3
cout << ((a >= b) ? "true" : "false") << endl;
cout << (a() ? b() : c( x - 2 )) << endl;
...

Hope this helps.
Topic archived. No new replies allowed.