Initialize sparse static array

后端 未结 2 933
猫巷女王i
猫巷女王i 2020-12-22 03:05

I need to initialize a static array. Not all of the values are sequential.

Something like this works fine for a sequential array:

class Foo {

  publ         


        
2条回答
  •  不思量自难忘°
    2020-12-22 03:52

    I would suggest you to use std::map (or unordered_map if you have C++11 support) instead of the array. You can then insert into this map with the code : m[67] = "Sun" and retrieve items using std::string s = m[67];.

提交回复
热议问题