Let's say I have a struct defined as so:
struct Barre {
int startString;
int endString;
Barre() { startString = endString = -1; }
Barre(int s, int e) : startString(s), endString(e) {}
bool exists() { return startString > -1; }
};
I will create an instance of this struct like this, for example:
Barre b = Barre(2, 4);
Let's say I insert this into a std::map<int, Barre> which is a member of a class, with a key of, for example, 3.
If I then create another Barre as above and overwrite the value of the map at key 3 with this new instance of the Barre struct, do I need to explicitly delete the old Barre object that I'm overwriting to prevent memory leaks? Or does it not persist once it is no longer stored in a map in this way?
Thanks for any help.
newand especially notdeleteyourself, unless you are doing some pretty deep library development, or use some existing framework which requires you to use them for legacy reasons (for example with Qt you'll usenew, but don't needdelete, and C++11 doesn't yet havemake_uniquefunction). Instead, use smart pointers.structspecifically, which is completely irrelevant for the question. Astructis just the same as aclasswith all memberspublicas default. Nothing to do with dynamic memory management at all.structandclassare basically the same thing, and until that realization might have trouble formulating a suitable search engine query.