使用Boost Python公开带有带有数组参数的构造函数的类
Exposing a class with a constructor that has an array argument with Boost Python
我正在尝试使用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];
};
我还想公开构造函数,使用以下Boost代码:
class_<bool_array>("bool_array", init<bool*>())
.def_readwrite("bools", &bool_array::bools)
;
问题是我得到这个编译器错误:
error C2440: '=' : cannot convert from 'const bool [7]' to 'bool [7]'
我也试过
init<bool[7]>
和
init<bool[]>
to no avail
我确信我错过了一些明显的东西,但是我一直无法弄清楚我需要做什么来公开这个类。
谢谢
在钻研这个问题时,我了解到boost-python不支持直接暴露c风格的数组。相反,我选择使用vector:
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;
};
使用以下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)
;
相关文章:
- 赋值 boost::intrusive_ptr 而不调用构造函数?
- 在 boost::variant 中类 holden 的复制构造函数存在问题
- 如何通过 boost::p ython 重命名构造函数的关键字参数
- 无法将参数传递给 boost::thread 构造函数
- 为什么Boost Variant使用模板构造函数而不是Boost::beast::websocket::stream的移
- 如何使用boost::hana::unpack和构造函数,而不是函数
- "非静态数据成员之前需要构造函数" - 我是否使用"boost::variant"
- Boost::msm 如何使用非默认构造函数初始化state_machine_def和 msm::front::sta
- 将动态分配对象传递到 boost::any 构造函数中
- Boost Python - 用参数包装构造函数
- C 从类的构造函数运行Boost线程
- 带有 Boost.Python 的私有构造函数
- Boost.Python - 参数化构造函数的错误
- 如何将构造函数参数转发到 boost::optional
- Boost-Spirit(X3)解析,没有默认构造函数
- 不能在构造函数中使用 boost.asio 解析器
- Boost::序列化 - 如何序列化需要数据分配但没有默认构造函数的数据结构
- 在 boost::lockfree:queue 默认构造函数的情况下断言失败
- 具有多个数组的类的构造函数启动器列表(C++11 是可以的,boost 和 std::vector 不是)
- C++:为什么 boost::p tr_vector 调整大小需要对象具有默认构造函数