Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.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++_Class_Boost_Constructor - Fatal编程技术网

使用具有Boost Python数组参数的构造函数公开类

使用具有Boost Python数组参数的构造函数公开类,python,c++,class,boost,constructor,Python,C++,Class,Boost,Constructor,我正在尝试使用Boost Python导出一个类,如下所示: struct bool_array { bool_array(bool constructor_bool[7]) { for(unsigned int i=0; i < 7; i++) bools[i] = constructor_bool[i]; } bool bools[7]; }; 我也试过了 init<bool[7]> init

我正在尝试使用Boost Python导出一个类,如下所示:

struct bool_array
{
    bool_array(bool constructor_bool[7])
    {
        for(unsigned int i=0; i < 7; i++)
            bools[i] = constructor_bool[i];
    }

    bool bools[7];
};
我也试过了

init<bool[7]>
init

init
无济于事

我确信我遗漏了一些明显的东西,但我一直无法弄清楚我需要做什么来公开这个类


谢谢

当我开始思考这个问题时,我了解到boostpython不支持直接暴露C风格的数组。相反,我选择使用向量:

struct bool_array
{
    bool_array(std::vector<bool> constructor_bool)
    {
        for(unsigned int i=0; i < 7; i++)
            bools.push_back(constructor_bool[i]);
    }

     std::vector<bool> bools;
};
struct bool\u数组
{
bool_数组(std::vector constructor_bool)
{
for(无符号整数i=0;i<7;i++)
bools.push_back(构造函数bool[i]);
}
向量布尔;
};
使用以下boost python包装器:

typedef std::vector<bool> BoolVector;
bp::class_<BoolVector>("BoolVector")
    .def(bp::vector_indexing_suite<BoolVector>())
;

bp::class_<bool_array>("bool_array", bp::init<std::vector<bool>>())
    .def_readwrite("bools", &bool_array::bools)
;
typedef标准::向量增强因子;
bp::类_uu(“BoolVector”)
.def(bp::vector_indexing_suite())
;
bp::类(bool\u数组,bp::init())
.def_readwrite(“bools”&bool_数组::bools)
;
init<bool[]>
struct bool_array
{
    bool_array(std::vector<bool> constructor_bool)
    {
        for(unsigned int i=0; i < 7; i++)
            bools.push_back(constructor_bool[i]);
    }

     std::vector<bool> bools;
};
typedef std::vector<bool> BoolVector;
bp::class_<BoolVector>("BoolVector")
    .def(bp::vector_indexing_suite<BoolVector>())
;

bp::class_<bool_array>("bool_array", bp::init<std::vector<bool>>())
    .def_readwrite("bools", &bool_array::bools)
;