Coffeehouse Post

Single Post Permalink

View Thread: C++ Bool Help?
  • User profile image
    Blue Ink

    if (CoinResult = true)

    is not the same as

    if (CoinResult == true)

    Classic pitfall; some compilers warn you about this kind of things.

    Two ways to avoid this altogether:

    1) Reverse all your comparisons, so that the constant appears first. For instance,

    if (true = CoinResult)

    would produce a compile time error.

    2) At least for Boolean expressions, use implied conversion to bool:

    if (CoinResult)