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.

Required fields*

6
  • How's MyPointerHolder's copy constructor going to work if you don't record the size of the held array in a member somewhere? Commented Mar 24, 2010 at 16:48
  • Um, non-standard call to msize? NUL-terminate the contents of the array? Make it a template parameter instead of a constructor argument? You're right, as written the code will need changes to complete it. This is just an example, though. MyPointerHolder should in general take whatever constructor parameters it needs in order to perform a deep copy. Commented Mar 24, 2010 at 19:19
  • What's the advantage of MyPointerHolder over std::vector? Commented Mar 24, 2010 at 20:32
  • "each time you come to write one of those little helper classes, ask yourself whether there's a standard library class which does the same job for you. In my example, there are two strong candidates: std::string and std::vector<char>". I haven't specified the required behaviour of a deep copy for the dynamically-allocated data, it's possible that std::vector doesn't do the right thing. Commented Mar 24, 2010 at 23:30
  • @Steve: Sorry, it seems I didn't read thoroughly all the way to the end. Commented Mar 25, 2010 at 15:05