加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

c – 在boost :: python的类中公开public struct

发布时间:2020-12-16 21:48:16 所属栏目:Python 来源:网络整理
导读:我想用boost :: python将这个C类用于python代码 /* creature.h */class Human {private:public: struct emotion { /* All emotions are percentages */ char joy; char trust; char fear; char surprise; char sadness; char disgust; char anger; char anti

我想用boost :: python将这个C类用于python代码

/* creature.h */
class Human {
private:
public:
    struct emotion {
        /* All emotions are percentages */
        char joy;
        char trust;
        char fear;
        char surprise;
        char sadness;
        char disgust;
        char anger;
        char anticipation;
        char love;
    };
};

问题是如何在boost-python中公开这个公共属性

namespace py = boost::python;

BOOST_PYTHON_MODULE(example)
{
    py::class_
最佳答案
当类型通过Boost.Python公开时,它们被注入到current scope中.某些类型(例如与class_一起引入的类型)可以用作当前范围.

这是一个完整的注释示例:

#include 

交互式Python:

>>> import example
>>> e = example.Human.Emotion
>>> e

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读