Quote:Original post by etsuja
wait if DisplayString in my struct = StringToAdd and wppasswrd is getting passed to AddString isn't it already getting deleted when I delete my struct?
Not unless you have explicit code in
your struct's destructor to take care of those. You'll have memory leaks unless you call "delete" for everything you've called "new" for, and "delete[]" for everything you've called "new[]" for.
// delete FirstString calls...STRINGSTRUCT::~STRINGSTRUCT(){// you have to iterate through your linked list, and delete// all "DisplayString" like this// delete[] Next->DisplayString;// THEN You have to iterate through, deleting all "Next"... which might// blow the stack, if your linked list is very long (delete Next; would// recursively call the destructor STRINGSTRUCT::~STRINGSTRUCT())}
This is where smart pointers can really help you... with the "Next" pointers. If you declared "Next" a smart pointer in your struct, instead of just "STRINGSTRUCT *Next", it would mean you'd only have to explicitly go through and delete[] Next->DisplayString.
You'd no longer have to call "delete Next" in the destructor, and potentially blow the stack with a long linked list.
boost::shared_ptr and Loki::SmartPtr are good places to start.