Skip to main content

Posts

Showing posts from December 2, 2018

Smart Pointers in C++

* Smart pointer classes are defined in <memory> header, so we need to include "memory" header to use smart pointers. * The header gives access to three template based smart pointers each with unique features. * We get "unique_ptr", "shared_ptr", "weak_ptr" *  Unique pointer are type of smart pointers that can’t be copied.std::unique_ptr is a smart pointer that owns and manages another object through a pointer and disposes of that object when the unique_ptr goes out of scope. *  Shared pointer is much like “unique_prt” but we can make copies of it. *  Weak pointer is a special case of shared pointer. Weak pointer helps in breaking circular references.Destruction using weak pointer will not care about destruction of other objects referenced from this present object under destruction.