导出C++类(纯虚函数和虚函数)
大致做法就是为class写一个warp,通过get_override方法检测虚函数是否被重载了,如果被重载了调用重载函数,否则调用自身实现,最后导出的时候直接导出warp类,但是类名使用class,析构函数不需要导出,因为它会被自动调用
纯虚函数
编写C++函数实现
$ vim virt.h
#include
#include
// 用class会出现编译问题, 不知道是不是和boost::python里面的class产生了冲突
struct Base
{
virtual ~Base() { std::cout << "Base destructor" << std::endl; };
virtual int f() = 0;
};
struct BaseWrap : Base, boost::python::wrapper
{
int f()
{
return this->get_override("f")();
}
};
编写Boost.Python文件
$ vim virt_wrapper.cpp
#include
#include
#include
#include "virt.h"
using namespace boost::python;
using namespace boost::pyt