Top "Smart-pointers" questions

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

best practice when returning smart pointers

What is the best practice when returning a smart pointer, for example a boost::shared_ptr? Should I by standard …

c++ boost smart-pointers
Recommended usage of std::unique_ptr

What are recommended uses of a std::unique_ptr as to specifically where, when, and how is it is best …

c++ c++11 smart-pointers unique-ptr
"Downcasting" unique_ptr<Base> to unique_ptr<Derived>

I have a series of factories that return unique_ptr<Base>. Under the hood, though, they are providing …

c++ c++11 smart-pointers factory-pattern unique-ptr
Why can't a weak_ptr be constructed from a unique_ptr?

If I understand correctly, a weak_ptr doesn't increment the reference count of the managed object, therefore it doesn't represent …

c++ shared-ptr smart-pointers unique-ptr weak-ptr
Can Google Mock a method with a smart pointer return type?

I have a factory that returns a smart pointer. Regardless of what smart pointer I use, I can't get Google …

c++ unit-testing smart-pointers googlemock
How does a reference-counting smart pointer's reference counting work?

In other words, how does the implementation keeps track of the count? Is there a map-like object maintained which is …

c++ memory-management memory-leaks smart-pointers shared-ptr
Smart pointers/safe memory management for C?

I, and I think many others, have had great success using smart pointers to wrap up unsafe memory operations in …

c memory pointers c99 smart-pointers
Should I use C++11 emplace_back with pointers containers?

Having a usual Base -> Derived hierarchy, like: class Fruit { ... }; class Pear : Fruit { ... }; class Tomato : Fruit { ... }; std::vector<…

c++ c++11 smart-pointers
What's the difference between BSTR and _bstr_t?

Can anyone explain the difference between the types mentioned above and some sample usage to clearly explain the difference between …

c++ com smart-pointers
Bad practice to return unique_ptr for raw pointer like ownership semantics?

I've written a static factory method that returns a new Foobar object populated from another data object. I've recently been …

c++ smart-pointers unique-ptr ownership-semantics