Top "Smart-pointers" questions

An abstract data type that simulates a pointer while providing additional features, such as automatic garbage collection or bounds checking

std::auto_ptr to std::unique_ptr

With the new standard coming (and parts already available in some compilers), the new type std::unique_ptr is supposed …

c++ c++11 smart-pointers auto-ptr unique-ptr
Passing shared_ptr<Derived> as shared_ptr<Base>

What is the best method to go about passing a shared_ptr of a derived type to a function that …

c++ casting c++11 shared-ptr smart-pointers
Differences between std::make_unique and std::unique_ptr with new

Does std::make_unique have any efficiency benefits like std::make_shared? Compared to manually constructing std::unique_ptr: std::…

c++ c++11 c++14 smart-pointers unique-ptr
RAII and smart pointers in C++

In practice with C++, what is RAII, what are smart pointers, how are these implemented in a program and what …

c++ smart-pointers raii
Smart pointers: who owns the object?

C++ is all about memory ownership - aka ownership semantics. It is the responsibility of the owner of a chunk …

c++ memory-management smart-pointers ownership-semantics
Vector of shared pointers , memory problems after clearing the vector

I realized that after calling vector.clear() which hold shared pointers, the destructors of the object which own by shared_…

c++ memory vector smart-pointers
Should I assign or reset a unique_ptr?

Given the common situation where the lifespan of an owned object is linked to its owner, I can use a …

c++ c++11 smart-pointers unique-ptr
How to get the Object being pointed by a shared pointer?

I have a query. Can we get the object that a shared pointer points to directly? Or should we get …

c++ shared-ptr shared smart-pointers
When to use shared_ptr and when to use raw pointers?

class B; class A { public: A () : m_b(new B()) { } shared_ptr<B> GimmeB () { return m_b; } private: …

c++ smart-pointers
Why would I std::move an std::shared_ptr?

I have been looking through the Clang source code and I found this snippet: void CompilerInstance::setInvocation( std::shared_ptr&…

c++ c++11 shared-ptr smart-pointers move-semantics