Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • Thanks for the answer! But could you explain how using a smart pointer would release the restriction of dynamic allocation? I didn't quite get this part. Commented Jul 25, 2011 at 18:13
  • @Kos, with smart pointers you can hide the allocation/deallocation of the actual object from your users. They only see the encapsulating smart pointer, which to the outside world behaves like a statically allocated object. Commented Jul 25, 2011 at 20:40
  • @Kos, not in the strict sense, AFAIR. You pass in the object to be wrapped, which you have probably allocated dynamically at some point. Then the smart pointer takes ownership of it and ensures that it is properly destroyed when it is no more needed (the time of which is decided differently for different kinds of smart pointers). Commented Jul 26, 2011 at 7:35