[C++-sig] Calling python virtual function from C++

William Marié william.marie at gmail.com
Wed Jan 28 19:16:25 CET 2009


I have a little problem, i can't find a way to call a pure virtual function
from C++ on a Python object taking a specific class object as argument :

// Base Class for a component
class BaseCmp
	~BaseCmp() {};

// Base class
class Base
	Base() {};
	virtual ~Base() {};
	virtual void testVirtualPure( BaseCmp* pBaseCmp ) = 0;

struct BaseWrap : Base, bp::wrapper<Base>
	void testVirtualPure( BaseCmp* pBaseCmp )
		this->get_override("testVirtualPure")( pBaseCmp );

// Module TestScript
	// BaseCmp Class exposition
	bp::class_<BaseCmp,boost::noncopyable>("BaseCmp", bp::no_init)

	// Base Class Wrapper exposition
	bp::class_<BaseWrap, boost::noncopyable>("Base")
		.def( "testVirtualPure", bp::pure_virtual( &Base::testVirtualPure ) )

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

Does someone know how i can do  that ?

Thanks a lot
View this message in context: http://www.nabble.com/Calling-python-virtual-function-from-C%2B%2B-tp21711534p21711534.html
Sent from the Python - c++-sig mailing list archive at Nabble.com.

More information about the Cplusplus-sig mailing list