A sign in C++ I've never seen before: |=

后端 未结 5 1206
盖世英雄少女心
盖世英雄少女心 2021-01-25 03:31

I have some code here:

case MONITORTYPE_WUXGA_SXGA_WXGA:
    bResult |= (var == enum1);
    bResult |= (var == enum2);

Now i know what its doin

5条回答
  •  甜味超标
    2021-01-25 04:20

    For most binary operators in C++ (except comparison operators, relational operators and boolean operators), there exists a corresponding compound assignment operator, ♢=.

    That is, |= is simply the compound assignment operator for | which is bitwise or. Its use is completely equivalent to +=, *= etc. So

    a |= b;
    // is equivalent to
    a = a | b;
    

提交回复
热议问题