[C++-sig] Problem using the ptr() function

Stefan Seefeld seefeld at sympatico.ca
Wed Oct 26 15:45:07 CEST 2005


Emmanuel Taurel wrote:
> Hello everybody,
> 
>  
> 
> I am using Boost.python to interface a C++ set of classes. In one of my 
> C+++ class, I am calling a method implemented in Python with the
> boost “call_method” call. This method has one parameter of our own data 
> type and return a pointer to this type. I have installed converters for 
> this type as it is adviced in the FAQ “How can I automatically convert 
> my custom string type…..” If I call my method like this
> 
>  
> 
> MyType *ret = call_method<MyType *>(my_py_obj,”My_method”, my_ptr)
> 
>  
> 
> With my_ptr being a MyType *, it works. But if I call it like this
> 
>  
> 
> MyType *ret = call_method<MyType *>(my_py_obj,”My_method”, ptr(my_ptr)) 
> to avoid a copy, I received a run time error complaining that
> 
>  
> 
> “No Python class registered for C++…..”

I believe the reason is that strings in python are non-mutable, meaning that
you can't modify them in-place. Instead, string variables are rebound to a new
value when you modify them.

That is incompatible with the way you want your string type to be handled.

Regards,
		Stefan



More information about the Cplusplus-sig mailing list