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*

8
  • The RAII concept still applies, it is great to hear. At least I got that part right. But considering that std::shared_ptr<> is part of C++11 the way of Qt is not outdated. Rather the opposite. Commented Jun 12, 2014 at 13:04
  • Wait, I was saying that passing a raw pointer into a function, that would have to delete it explicitly is outdated. Passing smart pointers around is certainly not outdated. I don't know what Qt is doing these days. Commented Jun 12, 2014 at 13:08
  • I am junior so please no offence, but the shared object provided to the constructor of shared_ptr is not copied. You create the shared object, with new, then hand it over to shared_ptr. Commented Jun 12, 2014 at 13:19
  • Oh, no offence at all. :) The shared object is allocated immediately before constructing the shared_ptr, literally in the same statement ptr = shared_ptr<MyClass>(new MyClass), and then it is deleted by the shared_ptr's destructor when necessary. I suppose you can argue that this is not symmetric memory management, but I think it is pretty close to it. Commented Jun 12, 2014 at 13:35
  • Which is the odd wobbly bit The need for new outside shared_ptr. That part puzzles me. The purpose of the copy constructor is to omit this need. Is there objects that can't be copied ? Commented Jun 12, 2014 at 14:19