[C++-sig] problems downcasting intrusive_ptr.

Roman Yakovenko roman.yakovenko at gmail.com
Sat Feb 10 22:35:01 CET 2007


On 2/10/07, Lucio Moser <lucio at image-engine.com> wrote:
> Hello,
>
> I created a factory function that returns an intrusive pointer for a
> derived class.
> The returned pointer is for the base class, but boost.python apparently
> downcast it correctly.
> I can call methods from the derived class with no problem.
> But then, if I pass that object to any function that requires a derived
> pointer it will fail.
>
> If I use shared_ptr instead. It works fine.
>
> Any ideas?

I could be wrong!

Take a look on http://boost.cvs.sourceforge.net/boost/boost/boost/python/converter/shared_ptr_from_python.hpp?view=markup
file. I think this custom converter is exactly the reason why you can do this
with shared_ptr and cannot do this with other smart pointer.

Even in C++, in order to do down casting you should use special API
( http://www.boost.org/libs/smart_ptr/intrusive_ptr.html#dynamic_pointer_cast )
Of course, Boost.Python is not aware of this API and you should help
it a little.

Introducing your own intrusive_ptr_from_python class should help.

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/



More information about the Cplusplus-sig mailing list