std::map default value for build-in type

后端 未结 4 2029
-上瘾入骨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 08:06

    The default value of class-type objects is that set by the default constructor of the class. For built-in types the default value is 0.

    But note that there is a difference between a built-in variable that isn't initialized, and one initialized to its default value. A built-in that is not initialized will probably hold whatever value was in that variable's memory address at the time.

    int i;          // i has an arbitrary undefined value
    int x = int();  // x is 0
    

提交回复
热议问题