For non-c++11 systems: how about using a helper function and make month_map
a static const member of date
as it looks like you never wan't to change the association of the month's name with it's number, do you? This way month_map
is initialized in your cpp-File and not in your constructor where it just messes things up. (Maybe you'll have several constructors in the future then you'll have to write a lot of boilerplate code)
const std::map<string, int> createMonthMap()
{
std::map<string, int> result;
// do init stuff
return result;
}
const std::map<string, int> date::month_map(createMonthMap());