Board index FlightGear Development

In C++, What is meant here?

FlightGear is opensource, so you can be the developer. In the need for help on anything? We are here to help you.
Forum rules
Core development is discussed on the official FlightGear-Devel development mailing list.

Bugs can be reported in the bug tracker.

In C++, What is meant here?

Postby jaxsin » Wed Apr 27, 2016 2:40 am

In C++ and most of the SG code I see things like this, what is the significance of the return line. Is this some sort of funny cast to a bool? How is this different then return(err); or return(bool(err));?

Code: Select all
# err will be either an 0 or -1.
bool SGPath::remove()
{
    ...
    return (err == 0)
}
jaxsin
 
Posts: 395
Joined: Mon Dec 28, 2015 4:54 pm

Re: In C++, What is meant here?

Postby curt » Wed Apr 27, 2016 3:15 am

(err == 0) is a conditional statement, it evaluates to true or false. It is equivalent to:

if (err == 0) {
return true;
else {
return false;
}

It's just a more compact way to express that.
curt
Administrator
 
Posts: 1168
Joined: Thu Jan 01, 1970 1:00 am
Location: Minneapolis, MN

Re: In C++, What is meant here?

Postby jaxsin » Wed Apr 27, 2016 12:00 pm

thank you, I did realize this after I posted it here and to Hooray. Sorry Horray for the spam.

It was getting late and at first I am not sure what I thought it meant.
jaxsin
 
Posts: 395
Joined: Mon Dec 28, 2015 4:54 pm


Return to Development

Who is online

Users browsing this forum: No registered users and 14 guests