I am trying to use std::shared_ptr
in my code. I have seen there have been other questions on the subject, but I am still getting a compiler error. Have I got t
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() );
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:
std::shared_ptr
. 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() );