小编Gre*_*nci的帖子

如何定义“operator()”C++ 类方法的 python pybind11 绑定?

假设我有一个简单的 C++ 类

class MyClass{
     //constructor
     MyClass(int value):_value(value){};

     void operator()(AnotherClass& const b){
     // Do something with b object
     }

    private:
      int _value;
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用 pybind11 创建此类的 Python 绑定。如何绑定operator()方法?

此绑定将用于将此类的对象传递给需要回调函数作为参数的函数。

c++ python callback pybind11

3
推荐指数
1
解决办法
2000
查看次数

标签 统计

c++ ×1

callback ×1

pybind11 ×1

python ×1