[C++-sig] Re: reference counting pointers
David Abrahams
dave at boost-consulting.com
Fri Jul 18 01:57:04 CEST 2003
"Dusty Leary" <dleary at ttlc.net> writes:
> Hi,
>
> Can someone give me example of a ResultConvertorGenerator (or whatever is
> required) so that addref/decref calls get called on an object?
>
> Currently, I am using boost::intrusive_ptr, which does almost what I want.
>
> All my class bindings are defined like so: class_<A, intrusive_ptr<A>
>>("A"); class_<B, intrusive_ptr<B>, bases<A> >("B"); etc...
>
> The problem is that functions which accept an intrusive_ptr<A>, when called
> with an intrusive_ptr<B>, cause boost.python errors (no valid type found).
Try
implicitly_convertible<intrusive_ptr<B>, intrusive_ptr<A> >();
Of course, if you just use shared_ptr instead, none of that is needed
;-)
> So, I would like to replace most of the uses of intrusive_ptr<A>
> with A* (in method signatures), and just have my C++ implementations
> use intrusive_ptr internally. This way, the polymorphic thing will
> work out ok, with boost wrapping B* and calling foo(A*) rather than
> wrapping intrusive_ptr<B> and failing to call foo(intrusive_ptr<A>).
If you really want to do that, the only way is to write thin wrapper
functions for each [member] function you're wrapping.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list