0

I recently wrongly declared an int as a bool and got no type error from the g++ compiler. Then I tried it again for testing and it compiles fine. Can someone explain why this is acceptable behaviour? Shouldn't the compiler give me a warning at least when i try to ++ a boolean or when i assign a bool as integer.

int main(int argc, char** argv)
{
    bool x = 0;
    x++;
    x++;
    cout << x << "\n";
    return 0;
}
Naveen Sharma
  • 1,057
  • 12
  • 32

1 Answers1

1
  • With the old standards (C++98) it is not an error.
  • With the new standards incrementing a boolean is deprecated. (C++11)
  • You can use incrementation on a boolean until C++17.
mustafagonul
  • 1,139
  • 1
  • 15
  • 32