Kaushik Reddy
Kaushik Reddy

Reputation: 85

function returning bool works even though it returns 1 or 0

bool CWaypoint::less(CWaypoint const &wp_right)
{
    bool result;
    CWaypoint temp1;

    (calculateDistance(temp1) > temp1.calculateDistance(wp_right)) ?
            result = 1 : result = 0;

    return result;
}

why don't I get an error even when I am not returning a bool type ?

Upvotes: 1

Views: 114

Answers (1)

AlexD
AlexD

Reputation: 32566

An integer-to-boolean conversion takes place. From the C++ standard:

4.12 Boolean conversions [conv.bool]

A prvalue of arithmetic, unscoped enumeration, pointer, or pointer to member type can be converted to a prvalue of type bool. A zero value, null pointer value, or null member pointer value is converted to false; any other value is converted to true.

Upvotes: 6

Related Questions