error: invalid initialization of non-const reference of type ‘bool&’ from an rvalue of type ‘std::vector::reference {aka std::_Bit_reference}’

后端 未结 2 606
一个人的身影
一个人的身影 2020-12-19 04:22

Why do I get the error: invalid initialization of non-const reference of type ‘bool&’ from an rvalue of type ‘std::vector::reference {aka std::_Bit_reference}’?

<
2条回答
  •  不思量自难忘°
    2020-12-19 05:13

    Normally, what you've assumed is the case, for literally any vector except vector. The original C++98 standard specified that as a bit-packed vector, and so references to the individual elements are impossible.

    This has since been recognized as an inconvenient mistake, but backward compatibility means that it can't be changed now.

提交回复
热议问题