std::map::operator[]

前端 未结 2 1943
星月不相逢
星月不相逢 2021-01-21 07:43

I was doing a simple map program but ended up with this question. The c++ doc says this:

Access element If k matches the key of an element in the container, the func

2条回答
  •  暖寄归人
    2021-01-21 08:24

    The statement of "using its default constructor" is confusing. More precisely, for std::map::operator[], if the key does not exist, the inserted value will be value-initialized.

    When the default allocator is used, this results in the key being copy constructed from key and the mapped value being value-initialized.

    For int, it means zero-initialization.

    4) otherwise, the object is zero-initialized.

提交回复
热议问题