I have std::map I'm trying to initialize using an initialization list. I do this in two places, in two different ways. The first one works, and the other causes the error indicated in the header.
Here's the one that works:
void foo() { static std::map<std::string, std::string> fooMap = { { "First", "ABC" }, { "Second", "DEF" } }; }
While this is not:
class Bar { public: Bar(); private: std::map<std::string, std::string> barMap; }; Bar::Bar() { barMap = {
Why am I getting an error when trying to initialize a class member, and does the static map work? At the moment, I can fill the element by first creating a local variable, and then replacing it with the following element:
Bar::Bar() { std::map<std::string, std::string> tmpMap = { { "First", "ABC" }, { "Second", "DEF" } }; barMap.swap(tmpMap); }
However, this seems rather contradictory compared to just filling the element directly.
EDIT: Here is the compiler output.
c ++ c ++ 11
manabreak
source share