std::map default value for build-in type

后端 未结 4 2042
-上瘾入骨i
-上瘾入骨i 2020-11-30 07:15

Recently, I was confused by the std::map operator[] function. In the MSDN library, it says: \"If the argument key value is not found, then it is inserted along with the defa

4条回答
  •  一个人的身影
    2020-11-30 07:59

     |expression:   | POD type T                               | non-POD type T
     ==================================================================================================
     | new T         | not initialized                          | default-initialized
     | new T()       | always default-initialized               | always default-initialized
     | new T(x)      | always initialized via a constructor     | always initialized via a constructor
    

    As far as i know, stl uses new T() for default values, so it will be default-initialized, in case of int to 0.

提交回复
热议问题