Double Negation in C++

后端 未结 14 2857
你的背包
你的背包 2020-11-22 10:40

I just came onto a project with a pretty huge code base.

I\'m mostly dealing with C++ and a lot of the code they write uses double negation for their boolean logic.

14条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 11:07

    If variable is of object type, it might have a ! operator defined but no cast to bool (or worse an implicit cast to int with different semantics. Calling the ! operator twice results in a convert to bool that works even in strange cases.

提交回复
热议问题