>> Thanks for the info on delete [] everyone!
Note that you should almost never be using delete[] in an actual C++ program, because there are few reasons to use a dynamically allocated array. If you think you need new[] and delete[], use vector instead.
Yes it does.
Main creates a *pointer, and then inserts it into a list.
Is that copy by value? So delete the pointer after inserting?
Code:string x; cin >> x; Element* pointerToElement = new Element(x); Set* pointerToSet = ... ... pointerToSet->Insert(pointerToElement); // Delete pointerToElement?
Last edited by Paul22000; 07-08-2008 at 05:23 PM.
It depends on what the Insert function does. Normally, you don't want to delete the pointer after calling insert, but if the set is storing objects and not pointers, then maybe you do.
Do you have the code or the documentation on what Insert is doing exactly?
If the Set owns the objects it holds (i.e. it is storing objects or allocating its own pointers), I wouldn't even be using new in the first place to create the Element, I'd create a local variable.