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

前端 未结 7 1743
野趣味
野趣味 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.

提交回复
热议问题