[C++-sig] custom smart pointers
Roman Yakovenko
roman.yakovenko at gmail.com
Tue Aug 29 19:48:57 CEST 2006
Hi. I am working on some project that defines smart pointer and uses
it allover the place.
I have a problem for some reason I am not able to call functions that takes the
smart pointer instantiation as argument. The error I get is ArgumentError:
ArgumentError: Python argument types in
custom_smart_ptr_classes.ref_get_value(add_x_t)
did not match C++ signature:
ref_get_value(my_smart_ptr_t<controllers::controller_i> {lvalue} a)
Code high level:
template<T>
class my_smart_ptr_t{...}
struct controller_i{
virtual int get_value() const = 0;
};
struct add_x_t : controller_i{
int m_value;
virtual int get_value( ){ return m_value + get_add_value(); }
virtual int get_add_value(){ return 0; }
};
int get_value( my_smar_ptr_t<controller_i> c ){ return c->get_value(); }
In order to export this code, I wrote next code:
namespace boost{ namespace python{
controller_i* get_pointer( my_smart_ptr_t< controller_i > const& p )
{ return p.get(); }
template <>
struct pointee< my_smart_ptr_t< controller_i > >
{ typedef controller_i type; };
//same code for add_x_t class
...
}}
Because both classes contains virtual function I create class-wrapper
for every class.
Classes and function registration is pretty simple. After this I add
next registration code:
register_ptr_to_python< my_smart_ptr_t< controller_i > >();
register_ptr_to_python< my_smart_ptr_t< add_x_t > >();
implicitly_convertible< my_smart_ptr_t< add_x_t >, my_smart_ptr_t<
controller_i > >();
Python code:
import my_module
add_x = my_module.add_x_t()
my_module.get_value( add_x ) # raises the error I described earlier.
I think, I exposed my classes "by the book". May be I am missing something?
Thanks in advance.
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
More information about the Cplusplus-sig
mailing list