Advertisement

pybind11笔记Python处理C++结构体

阅读量:

系列文章

【pybind11笔记】eigen与numpy数据交互

【pybind11笔记】python调用c++函数

【pybind11笔记】python调用c++结构体

【pybind11笔记】python调用c++类

为自定义类型创建绑定

接下来,我们将通过一个更为复杂的案例进行说明,在此案例中,目标是为名为Pet的自定义C ++数据结构生成绑定。该数据结构的具体定义如下:

复制代码
    struct Pet {
    Pet(const std::string &name) : name(name) { }
    void setName(const std::string &name_) { name = name_; }
    const std::string &getName() const { return name; }
    
    std::string name;
    };
    
    
      
      
      
      
      
      
      
    

相关代码的绑定方式如下:

复制代码
    #include <pybind11/pybind11.h>
    
    namespace py = pybind11

全部评论 (0)

还没有任何评论哟~