[C++-sig] custom smart pointers

Alex Mohr amohr at pixar.com
Tue Sep 5 22:20:20 CEST 2006


>> Python code is next:
>> import custom_smart_ptr_classes as cspc
>> d = cspc.derived( 2 )
>> cspc.get_value( d )
>>
>> The last line raises next exception:
>>
>> ArgumentError: Python argument types in
>>     custom_smart_ptr_classes.get_value(derived)
>> did not match C++ signature:
>>     get_value(my_smart_ptr_t<base> a)
>>
>> Thank you.
> 
> Can somebody help me with this issue?
> 
> Thanks in advance.

In my experience, boost python needs a lot of hand holding to work well 
with custom smart pointers.

I think the first thing you need here is an rvalue from-python 
conversion for your smart pointers.  Register a conversion for each 
smart_ptr<T> that you expose to python.  And make sure you do it for 
smart_ptr<T>, not smart_ptr<wrapper<T> > in the case of polymorphic stuff.

I (semi)automate this in a custom def visitor.

Alex



More information about the Cplusplus-sig mailing list