proper safe way to delete a list of pointers.

Started by
3 comments, last by Nickels 20 years, 6 months ago
1) deleting each pointer from element 0 to n-1. 2) deleting each pointer from element n-1 to 0. 3) delete each pointer from element 1 to n-1 and then deleting the list.
Climb a mountain, every dawn.
Advertisement
I''d use an STL friendly smart-pointer and std::list.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
quote:Original post by Nickels
1) deleting each pointer from element 0 to n-1.

2) deleting each pointer from element n-1 to 0.
Either two is fine, and don''t forget to delete the list. However, like Magmai said, std::list is better.

so i would delete each element in the list.
then i delete the list by doing

1) delete list;

or

2) delete[] list;

im guessing this wouldnt change anything, so im guessing #2.
Climb a mountain, every dawn.
It entirely depends on how you create your list. I suspect that either method would be wrong.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement