0

Instead of using try/catch blocks everytime I need to construct any objects after allocating a block of memory for them with an allocator I use internally in my container, I would like to use a class derived from std::auto_ptr (I have no c++11 here) with an overridden destructor, so that it could deallocate the pointed memory and release the pointer afterwards. Are there any disadvantages in doing this?

Martin
  • 9,089
  • 11
  • 52
  • 87
  • Even though you have no C++11, you probably have `shared_ptr` and `unique_ptr` nonetheless (it's C++03 actually). If you don't, you still can use the implementation in boost. – J.N. Mar 12 '12 at 11:47
  • @PawelZubrycki the allocator I use is a template parameter, which defaults to the classic std::allocator – Martin Mar 12 '12 at 11:51

1 Answers1

0

If you don't mind using boost and boost::shared_ptr<>, you can provide a custom deleter. See the top 2 answers to this question.

Community
  • 1
  • 1
Moo-Juice
  • 38,257
  • 10
  • 78
  • 128