Simple question, I just want to initialize a map to be empty, instead of being a nullptr.
const std::map<std::string, std::string>* emptyDictionary;
I tried
const std::map<std::string, std::string>* emptyDictionary = {"", ""};
but obviously that’s not right.
Thanks guys.
You forgot to make any map at all — you just made a pointer! You can make the pointer point to a dynamically allocated map:
This map will be truly empty. If you add the initializer
{{"", ""}}, which you may well do, then you don’t actually have an empty map, but rather a map with one element which maps an empty string to an empty string.Note that you can never modify your map through the const pointer, so it’s a bit questionable why you’d want to do this.
Note also that wanton dynamic allocation is generally a poor programming style. There’s almost surely a better way to do whatever you need to do, or, based on your comment, you’re just grossly misunderstanding something: The best way to obtain a pointer is to take the address of an existing object: