BOOST.PYTHON如何公开boost :: shared_ptr的Typedef
boost.Python How to expose typedef of boost::shared_ptr?
我的C 类定义为:
class MyFuture {
public:
virtual bool isDone() = 0;
virtual const std::string& get() = 0;
virtual void onDone(MyCallBack& callBack) = 0;
virtual ~MyFuture() { /* empty */ }
};
typedef boost::shared_ptr<MyFuture> MyFuturePtr;
我使用boost.python将课程暴露于Python(此类从未在Python中创建,而是从API调用返回,因此noncopyable
):
BOOST_PYTHON_MODULE(MySDK)
{
class_<MyFuture, noncopyable>("MyFuture", no_init)
.def("isDone", &MyFuture::isDone)
.def("get", &MyFuture::get, return_value_policy<copy_const_reference>())
.def("onDone", &MyFuture::onDone)
;
}
来自Python,我像以下方式一样使用它:
import MySDK
def main():
# more code here ...
future = session.submit()
response = future.get
print response
if __name__ == "__main__":
main()
,但这导致python错误:
File "main.py", line 14, in main
future = session.submit()
TypeError: No to_python (by-value) converter found for C++ type: class boost::shared_ptr<class MySDK::MyFuture>
如何公开Typedef typedef boost::shared_ptr<MyFuture> MyFuturePtr;
?
update
使用boost.python更改类公开:
class_<MyFuture, boost::shared_ptr<MyFuture> >("MyFuture", no_init)
导致编译器错误:
boostpythonconverteras_to_python_function.hpp(21):
error C2259: 'MySDK::MyFuture' : cannot instantiate abstract class
class_<MyFuture, boost::shared_ptr<MyFuture>, boost::noncopyable>("MyFuture")
根据文档
http://www.boost.org/doc/libs/1_62_0/libs/python/doc/doc/html/reference/high-high high-level_components.html#high_le_level_level_level_boost_component
相关文章:
- C++:TypeDef使用元组
- 有没有一种方法可以通过"typedef"为重新定义的基本类型定义特征和强制转换运算符
- CLANG 编译器 说:变量"PTR"可能未初始化
- 为什么在使用typedef时类推导指南会失败
- 在以唯一ptr为值的C++映射中,动态内存何时会被销毁
- 尝试根据类中 typedef 的存在来专门化模板函数
- 将 ptr 传递给 ptr 到 A 作为参数传递给 A 的函数是不好的做法吗?
- 如何重新定义MPI_FLOAT,MPI_DOUBLE以 typedef 的方式
- typedef 枚举和枚举类有什么区别?
- 在类模板中使用 typedef 时出错
- 模板类中的 typedef 语句
- 在 typedef 内部使用 const 关键字和在 typedef 外部使用 const 关键字之间有区别吗?
- 如何将成员函数作为回调参数传递给需要"typedef-ed"自由函数指针的函数?
- 为共享 ptr 向量实现复制 c'tor?
- 字符和整数中 **(ptr+1) 的值差异
- C++:在不中断共享的情况下通过引用传递共享 PTR?
- 如何将派生类从基 ptr 分配给 nlohmann::json
- C++中"typedef"、"using"、"namespace"和"using namespace"有什么区别?
- 引用 std::shared:ptr 以避免引用计数
- 向前声明指向类的 typedef 指针