簡體   English   中英

用pybind11包裝C ++無效函數

[英]Wrapping C++ void functions with pybind11

我有一個C ++類,其中包含void函數,這些函數接受通過引用傳遞的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列表。

我的第二個問題是如何為C ++函數編寫Python綁定,以修改通過引用傳遞的STL向量的內容並返回void

pybind11/stl.h結果包括在c ++和pyhton之間的復制轉換中,請參見http://pybind11.readthedocs.io/zh/stable/advanced/cast/stl.html#automatic-conversion

要通過參考傳遞,請參見http://pybind11.readthedocs.io/en/stable/advanced/cast/stl.html#making-opaque-types部分

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM