Using std::map where V has no usable default constructor

后端 未结 9 1627
予麋鹿
予麋鹿 2020-12-05 13:11

I have a symbol table implemented as a std::map. For the value, there is no way to legitimately construct an instance of the value type via a default constructo

9条回答
  •  南方客
    南方客 (楼主)
    2020-12-05 13:27

    Use map::at(). map::operator [] will try to default-construct an element if the key provided does not already exist.

提交回复
热议问题