[C++-sig] Calling python virtual function from C++
David Abrahams
dave at boostpro.com
Thu Jan 29 16:38:32 CET 2009
on Thu Jan 29 2009, William Marié <william.marie-AT-gmail.com> wrote:
> Hi David,
>
> Here is the reproducible test ( just change the boost.strap and the python paths in
> the jamroot ) !!
> Thanks for your time
void testVirtualPure( BaseCmp* pBaseCmp )
{
this->get_override("testVirtualPure")( ptr( pBaseCmp ) );
} // ^^^^ ^
Creating Python objects that reference C++ objects by pointer is
dangerous; if you really want to do that, wrap the C++ pointer in
ptr(...). Otherwise Boost.Python will try to copy it. You declared
BaseCmp to be noncopyable, so no converter was registered that would
copy a BaseCmp object into a new Python object.
> David Abrahams a écrit :
>> on Wed Jan 28 2009, William Marié <william.marie-AT-gmail.com> wrote:
>>
>>
>>> I need to call my testVirtualPure function from C++ side : BaseCmp* bc = BaseCmp();
>>> Base* b = Base();
>>> b->testVirtualPure( bc );
>>>
>>> But this causes an error : TypeError: No to_python (by-value) converter found for
>>> C++ type: class
>>> BaseCmp
>>>
>>
>> The above doesn't compile, so you can't possibly be getting that
>> TypeError from it. Please post the exact complete, reproducible example
>> that causes youi problems, after reducing it to a minimal test case.
>>
>> Thanks,
>>
>
>
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
--
Dave Abrahams
BoostPro Computing
http://www.boostpro.com
More information about the Cplusplus-sig
mailing list