proper way to de-alloc list<type*> ?

Started by
10 comments, last by Tyson 20 years, 11 months ago
quote:Original post by civguy
I don''t know how it solves memory leaks either. If it was totally transparent, it would solve them. But now that I have to actively type
typedef boost::shared_ptr<string> SharedStringPtr;
And then use SharedStringPtr everywhere, so it''s actually more burden than adding a deleteContainer(cont); into the destructor.

As I said: "you could write your own smart pointer if you want to". This smart pointer could have an implicit constructor (boost::shared_ptr''s constructor is explicit) and an implicit convertion operator to the contained type (boost::shared_ptr doesn''t have an implicit convertion operator, you must go via the get member function), then it will be totally transparent.

[How To Ask Questions|STL Programmer''s Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
Advertisement
for neatness try:

  struct delete_object{  template <typename T>  void operator()(T* p){ delete p;}};for_each( myList.begin(), myList.end(), delete_object());myList.clear();  


HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats

This topic is closed to new replies.

Advertisement