Why can I use initializer lists on the right-hand side of operator += but not operator+?

后端 未结 3 1588
遇见更好的自我
遇见更好的自我 2021-01-03 20:15

This is a follow-up to an earlier question about why I can\'t use a brace-enclosed initializer as an argument to operator+, which was resolved by looking at this earlier que

3条回答
  •  抹茶落季
    2021-01-03 20:35

    += operator is a compound assignment. The standard explicitly permits initializer lists on the right-hand side of assignments:

    §8.5.4/1 [...] Note: List-initialization can be used

    ...

    — on the right-hand side of an assignment (5.17)

    §5.17 talks about all assignments, including compound ones:

    assignment-expression:
    - conditional-expression
    - logical-or-expression assignment-operator initializer-clause
    - throw-expression

    assignment-operator: one of
    = *= /= %= += -= >>= <<= &= ˆ= |=

提交回复
热议问题