I have People class names. I keep pointers to these people on the map.
map<string, People*> myMap;
To create new people, I use the maps [] operator.
myMap["dave"]->sayHello();
But that gives me segmentation errors and doesn't even call the constructor of the People class.
I also tried
myMap.insert( std::make_pair( "dave", new People() ));
But this has not changed anything, the constructor is still not being called, and the program disables the processing of this code with a segmentation error.
How do I access and manipulate a map using pointers in them? Why does not work above, I do not see compilation errors or warnings.
Any insight is much appreciated, thanks
source
share