If you had a function with a raw pointer
void f(T *t);
And you had a smart pointer to the T object, you can pass it to this function using get()
std::shared_ptr<T> sp{new T};
APIs that use raw pointers are common and still useful. I suggest you watch this part of the CppCon 2014 Herb Sutter talk, and possibly the parts around it.
You should not try to delete this pointer, the smart pointer classes assume that you will not do anything, and still free the managed object in your own destructors when the time comes (in the end, how would he know that you deleted it?).
The task of the smart pointer is to manage the object and delete it at the right time, if you want to manually control the lifetime of the object (usually not recommended), and then use the raw pointer.
If you want to take responsibility for unique_ptr , you can do this by calling release() .
source share