[C++-sig] Custom smart pointer with same behaviour as shared_ptr

David Abrahams dave at boost-consulting.com
Sun Apr 8 00:17:21 CEST 2007


on Mon Apr 02 2007, "Francis Moreau" <francis_moreau-AT-hotmail.com> wrote:

> Hi,
>
> I am passing Python objects to C++ through a shared_ptr smart pointer and 
> it's work well. However I need to have the same behaviour as shared_ptr but 
> with my own version of smart pointer. I try to register and expose my custom 
> smart pointer but I have this compilation error:
>
> boost/python/pointee.hpp(28) : error C2039: 'element_type': is not a member 
> of 'CountedObjPtr<T>'
>         with
>         [
>             T=PyCallEngineState
>         ]
>         boost/python/pointee.hpp(38) : see reference to class template 
> instantiation 'boost::python::detail::pointee_impl<false>::apply<T>' being 
> compiled
>         with
>         [
>             T=CountedObjPtr<PyCallEngineState>
>         ]
>         boost/python/register_ptr_to_python.hpp(17) : see reference to class 
> template instantiation 'boost::python::pointee<T>' being compiled
>         with
>         [
>             T=CountedObjPtr<PyCallEngineState>
>         ]
>         PythonModules.cpp(113) : see reference to function template 
> instantiation 'void 
> boost::python::register_ptr_to_python<CountedObjPtr<T>>(void)'being compiled
>         with
>         [
>             T=PyCallEngineState
>         ]

Please read http://www.boost.org/libs/python/doc/v2/pointee.html

However, be aware that you won't get exactly the "magic" shared_ptr
behavior described in
http://www.boost.org/libs/python/doc/v2/faq.html#xref unless your
pointer has a deleter just as shared_ptr does AND you do some extra
work to define special converters for it (and perhaps not even then; I
haven't looked into the details).


-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Don't Miss BoostCon 2007! ==> http://www.boostcon.com




More information about the Cplusplus-sig mailing list