You most likely don't want to use new
. Unlike in languages like Java, the new
keyword is not needed for every object creation in C++, and unlike in many other languages, objects created with new
are not automatically destroyed when you no longer need them. You instead have to delete them manually with delete
.
Also, new
does not return the newly created object itself but a pointer to it, allowing you to do nasty things like storing the pointer, later deleting the object and then accidentally attempting to access it through the stored pointer, which may crash the program.
All of this creates endless problems and bugs. Especially if you are a newbie (or if you gain more experience and think you can finally handle the complexity :)).
In C++, normal object creation doesn't require new
. It is much simpler. Your first line is already object creation:
multimap <int, string> prioritized_list;
No need for new
here.