[C++-sig] Returning pointer to abstract class from pure virtual class method

Roman Hwang hwang.roman at gmail.com
Mon Oct 12 08:59:58 CEST 2009


I'm new to Python, but really want to use it with my C++ code.

I faced a problem while returning pointer to abstract class from pure
virtual class method.
I tried to search the web, but found nothing.

struct ICoreWrapper : ICore, wrapper<ICore>
	virtual IRegistry* CreateRegistry()
		{ return this->get_override("CreateRegistry")(); }


struct IRegistryWrapper : IRegistry, wrapper<IRegistry>
	virtual void DoSomestuff()
                        { return this->get_override("DoSomestuff")(); }

ICore* CreateCoreW()
	return new CCore;

	class_<IRegistryWrapper, boost::noncopyable>("IRegistry")
		.def("DoSomestuff", pure_virtual(&IRegistry::DoSomestuff))

	class_<ICoreWrapper, boost::noncopyable>("ICore")
		.def("CreateRegistry", pure_virtual(&ICore::CreateRegistry),

	def("CreateCore", CreateCoreW,

The Python code looks like this:
>>> import CorePy
>>> c = CorePy.CreateCore()
>>> b = c.CreateRegistry()

I get Debug Error

Run-Time Check Failure #0 - The value of ESP was not properly saved
across a function call.
This is usually a result of calling a function declared with one
calling convention with a function pointer declared
with a different calling convention.

Please tell me what I do wrong.
Or whether this code is supported or not.


Roman Hwang.

More information about the Cplusplus-sig mailing list