C++ std::shared_ptr usage and information
std::tr1::shared_ptr
is part of the TR1 additions to the C++ STL.
With GCC, it is available either through #include <tr1/memory>
(GCC 4.1) or #include <memory>
(GCC 4.3)
You were also asking for references or literature...
I found 3 articles that may help:
- An article on Smart Pointers, which is an overview good for a general understanding.
- An actual reference for
std::shared_ptr
. - A great tutorial discussing every method of TR1
shared_ptr
along with sample code.
Also a comment on your code example:
std::shared_ptr<A*> ptr_A = shared_ptr( new A() );
The template argument should be A instead of A* :
std::shared_ptr<A> ptr_A = shared_ptr( new A() );
If you don't have shared_ptr
in std you can use it from boost.
#include <boost/shared_ptr.hpp>
boost::shared_ptr<A> ptr_A( new A() );