Kinda yes.
Kinda is because std::shared_ptr
is slower than raw pointers. Object won't get deallocated if you passed a copy of the shared pointer somewhere else, but it will get deallocated once all the shared pointers to it are gone.
Furthermore, the reference counter tracker is safe-thread.
Also ClassA
need not have a virtual destructor for the shared pointer to work properly.
As you can imagine, these features are costly.
If you need same performance as raw pointers, you can achieve it by utilizing std::unique_ptr
. Though, it is non-copyable and its usage might confuse newly introduced to C++11.
Aside from that, it is recommended to use std::make_shared
and std::make_unique
for initializing said smart pointers.