Top "Smart-pointers" questions

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

How to perform a dynamic_cast with a unique_ptr?

I have a class hierarchy as follows: class BaseSession : public boost::enable_shared_from_this<BaseSession> class DerivedSessionA : …

c++ boost smart-pointers unique-ptr dynamic-cast
Passing unique_ptr to functions

I'm trying to "modernize" some existing code. I have a class which currently has a member variable "Device* device_". It …

c++ smart-pointers unique-ptr
smart pointers and arrays

How do smart pointers handle arrays? For example, void function(void) { std::unique_ptr<int> my_array(new …

c++ c++11 smart-pointers
How to assign the address of an existing object to a smart pointer?

#include <memory> class bar{}; void foo(bar &object){ std::unique_ptr<bar> pointer = &object; } …

c++ smart-pointers c++14 unique-ptr
Is it correct to return null shared_ptr?

For example, there is a function that finds an object and returns shared_ptr if object is found, and must …

c++ shared-ptr smart-pointers weak-ptr
When should I use raw pointers over smart pointers?

After reading this answer, it looks like it is a best practice to use smart pointers as much as possible, …

c++ pointers boost smart-pointers
How to check memory allocation failures with new operator?

Just recently I switched the language of my project to use C++ from C. With C, I used malloc and …

c++ memory-management smart-pointers
unique_ptr<T> lambda custom deleter for array specialization

I recently started porting lots of my existing C++ application code to over to C++11 and now that I am …

c++ lambda c++11 smart-pointers unique-ptr
What C++ Smart Pointer Implementations are available?

Comparisons, Pros, Cons, and When to Use? This is a spin-off from a garbage collection thread where what I thought …

c++ smart-pointers c++-faq
Why do C++ libraries and frameworks never use smart pointers?

I read in a few articles that raw pointers should almost never be used. Instead they should always be wrapped …

c++ api pointers smart-pointers