Defining double exclamation?

前端 未结 7 2094
失恋的感觉
失恋的感觉 2021-02-04 06:43

I understand what a double exclamation mark does (or I think I understand) but I am not sure how it is defined on a random object. For example in the code snippet below:

7条回答
  •  没有蜡笔的小新
    2021-02-04 06:56

    !! is not a single token in C++ and simply resolves to applying the ! operator twice.

    As a is a pointer and not an object of class type the ! cannot be overloaded. It is defined to return true if a is a null pointer and false otherwise.

    The second application of ! simply negates the result of the first !.

    The expression !!a is equivalent to a != 0.

提交回复
热议问题