I want to add a std::map m_mapName in the initialization list of the constructor.
If I type m_mapName() in the constructor's init list, the compiler accepts it.
But, is it correct? If it is not correct, how can I add the map to the initialization list?
Then, I do several insertions in the map. What is a more elegant way of inserting values, so I don't call insert function everytime?
More info:
Just like in : C++, can I statically initialize a std::map at compile time?, the compiler doesn't accept syntax like:
std::map<int, char> example = { (1,'a'),
(2, 'b'),
(3, 'c') };
Cannot use Boost. My code looks like this:
* className.h: *
typedef std::map <uint16_t, int> mapType;
typedef std::pair <uint16_t, int> mapPair;
className{
private:
mapType m_mapName;
}
* className.cpp: *
className::className () :
m_mapName()
{
...
m_mapName.insert(mapPair(someMapValue1, 0));
m_mapName.insert(mapPair(someMapValue2, 0));
m_mapName.insert(mapPair(someMapValue3, 0));