1
私は、メモリがC++側で処理されるC++インスタンスを参照するpybind11でPythonバインディングを作成しようとしています。私のpython example.dog
の間のリンクを作成する方法についてこだわっているpybind11でC++に割り当てられたオブジェクトを参照する
import <pybind11/pybind11>
struct Dog {
void bark() { printf("Bark!\n"); }
};
int main()
{
auto dog = new Dog;
Py_Initialize();
initexample(); // Initialize the example python module for import
// TBD - Add binding between dog and example.dog .
PyRun_StringFlags("import example\n"
"\n"
"example.dog.bark()\n" // Access the C++ allocated object dog.
, Py_file_input, main_dict, main_dict, NULL);
Py_Finalize();
}
およびC++ dog
変数:ここではいくつかのサンプルコードです。
私はDog
の新しいインスタンスを割り当てますが、それは私が望むものではないため、py:class_<Dog>.def(py::init<>())
を使用することはできません。