Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在boost::python的类中公开公共结构 我想在Python代码上使用这个C++类,用Boosi::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; }; };_C++_Python_Wrapper_Boost Python - Fatal编程技术网

在boost::python的类中公开公共结构 我想在Python代码上使用这个C++类,用Boosi::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的类中公开公共结构 我想在Python代码上使用这个C++类,用Boosi::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; }; };,c++,python,wrapper,boost-python,C++,Python,Wrapper,Boost Python,问题是如何在boostpython中公开这个公共属性 namespace py = boost::python; BOOST_PYTHON_MODULE(example) { py::class_<Human>("Human"); // I have not idea how put the public struct here } namespace py=boost::python; BOOST_PYTHON_模块(示例) { py::类_uuz(“人

问题是如何在boostpython中公开这个公共属性

namespace py = boost::python;

BOOST_PYTHON_MODULE(example)
{
    py::class_<Human>("Human");
        // I have not idea how put the public struct here
}
namespace py=boost::python;
BOOST_PYTHON_模块(示例)
{
py::类_uuz(“人类”);
//我不知道如何把公共结构放在这里
}

当类型通过Boost.Python公开时,它们被注入到。某些类型,例如随
引入的类型,可以用作当前范围

下面是一个完整的注释示例:

#包括
结构人
{
结构情感
{
焦乐;
// ...
};
};
BOOST\u PYTHON\u模块(示例)//将范围设置为示例
{
名称空间python=boost::python;
{
python::scope in_human=//定义example.human和set
python::class_u979;(“Human”);//作用域到example.Human
python::class_(“Emotion”)//定义example.Human.Emotion
.add_属性(“快乐”和人类::情感::快乐)
;
}//还原作用域,作用域现在为
}//示例
交互式Python:

>>导入示例
>>>e=例子。人类。情感
>>>e
>>>hasattr(即“欢乐”)
真的