C++
2
Вклад в тег
#include <boost/python.hpp>
using namespace boost;
using namespace boost::python;
struct Foo
{
virtual ~Foo() {}
virtual void Print() = 0;
};
struct FooWrap : Foo, wrapper<Foo>
{
void Print()
{
this->get_override("Print")();
}
};
void ProcessFoo(Foo *obj) { obj->Print(); }
BOOST_PYTHON_MODULE(hello_ext)
{
class_<FooWrap, boost::noncopyable>("Foo")
.def("Print", pure_virtual(&Foo::Print));
def("ProcessFoo", &ProcessFoo);
}
import hello_ext
class NewFoo(hello_ext.Foo):
def Print(self):
print 'Print call'
hello_ext.ProcessFoo( NewFoo() )
E:Temppython>"d:/Coding/Python 2.7/python.exe" hello.py
Print call