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 PostSo in my program i've dynamically allocated an array of 3 state objects (to which list points to the beginning) and each of these objects contains pointers to dynamically allocated strings. In my whole program, I managed to get everything except the deletion to work properly. If I'm doing this …
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,138
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.