If I have a dynimcally allocated array of objects and each of these objects contains a pointer to a string, when I use the 'delete' function to return memory, do I have to go through each array element and free each string individually or does the 'delete' take care of that for me in C++?
degamer106 0 Junior Poster
Recommended Answers
Jump to PostI believe that you have to free each individual member of an object first (assuming of course, that the object contains data members that were dynamically allocated), before you can delete the actual object itself.
That's what the object's destructor is for; so use it wisely. If the actual …
Jump to Post1. If your destructors are always calling delete, then every single constructor you have MUST initialise the pointers to at least 0.
2. Your copystate function just makes copies of the pointers (you now have two pointers pointing at the same memory). Bad things happen when you try and …
All 6 Replies
John A 1,896 Vampirical Lurker Team Colleague
degamer106 0 Junior Poster
John A 1,896 Vampirical Lurker Team Colleague
degamer106 0 Junior Poster
John A 1,896 Vampirical Lurker Team Colleague
Salem 5,265 Posting Sage
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.