用 pybind11 包装C++ void 函数
Wrapping C++ void functions with pybind11
我有一个包含 void 函数的C++类,这些函数采用通过引用传递的 STL 向量并修改其中一个向量的内容。例如:
void somefunction(std::vector<double> &result, std::vector<double> &array1, std::vector<double> &array2) {some calculations}
pybind11 绑定如下所示:
.def("somefunction", &somefunction)
我已经包含了"pybind11/stl.h"头文件,它处理STL容器和python等价物之间的自动转换,在Python中,我用Python列表调用somefunction
,但我不确定C++层是否可以修改result
Python列表。
我当时的问题是如何编写Python C++函数的绑定,这些函数修改通过引用传递的 STL 向量的内容并返回void
。
包括 c++ 和 pyhton 之间复制转换pybind11/stl.h
结果,请参阅 http://pybind11.readthedocs.io/en/stable/advanced/cast/stl.html#automatic-conversion
要通过引用,请参阅第 http://pybind11.readthedocs.io/en/stable/advanced/cast/stl.html#making-opaque-types 节
相关文章:
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- 在c++类上调用void函数
- C++为什么尽管我调用了void函数,它却不起作用
- 如何从void函数输出字符串
- 如何将指针从一个void函数传递到另一个C++
- 为什么我在使用void函数时得到错误代码C2276
- 指针没有更新它在void函数内部指向的值
- 为什么我们要为avl树实现返回一个指向节点的指针,而不是void函数
- void 函数可以传递值参数吗?
- 在 void 函数中使用 #include 变量C++
- 如何在 C++ 中将 void 函数传递给 void 指针
- 使用运算符调用 void 函数时出错<set>
- C++ 随机数生成器:尝试将结果作为向量获取,但通过制作 void 函数来执行此操作而出现错误
- C++ :: 如何捕获由 void 函数创建的矩阵
- 如何将一个 void 函数传递给另一个 void 函数?
- 当我使用 void 函数的返回值(通过强制转换函数指针)时,究竟会发生什么?
- C++命名空间中调用 void 函数的错误
- 当数组位于两个循环之间时,您可以调用数组的 void 函数吗?
- 结构新手,我对如何从 void 函数中返回值并将其放入另一个函数感到困惑
- 查找素数:错误:控件到达非void函数的末尾