Why is a C++ bool var true by default?

前端 未结 7 1720
野趣味
野趣味 2020-12-05 18:51

bool \"bar\" is by default true, but it should be false, it can not be initiliazied in the constructor. is there a way to init it as false without making it static?

相关标签:
7条回答
  • 2020-12-05 19:52

    C / C++ don't initialize variables for you at all. The memory location which is now in use by bar had a value in it which is interpreted as "true". This will not always be the case. You must initialize it in your constructor.

    0 讨论(0)
提交回复
热议问题