我正在尝试将带有一些2D数组成员变量的C ++类传递给Python脚本。 2D数组直接分配到类中,与构造函数无关。我正在使用boost_python库进行此转换,并使用add_property / reference_existing_object函数的包装函数,期望从C ++脚本的双指针创建一个新的Python 2D数组。
然而,我得到一个错误,告诉我在处理数组时boost不能从const double转换为double。但是如果它们不应该首先将数组设置为const?我可能会在这里。我刚开始提升,自从我编写C ++以来已经有一段时间了,所以我希望你们中的一些人能够以一种简单的方式帮助解释这个问题:)如果我的方法不是这样的话,我怎么能通过这些数组呢?
我在这里发布了类和包装函数以供参考。
class Interface
{
public:
double zUpPatch1[NVALUES_UPSWEEP][N_VALUES_IN_TUPLE+1];
double zUpPatch2[NVALUES_UPSWEEP][N_VALUES_IN_TUPLE+1];
double zDownPatch1[NVALUES_UPSWEEP][N_VALUES_IN_TUPLE+1];
double zDownPatch2[NVALUES_UPSWEEP][N_VALUES_IN_TUPLE+1];
bool bNewData[N_VALUES_IN_TUPLE+1];
int mrows, ncols;
Interface();
void GetRawData(int);
};
Interface::Interface()
{
mrows = NVALUES_UPSWEEP;
ncols = N_VALUES_IN_TUPLE+1;
}
BOOST_PYTHON_MODULE(GetRawDataPy_ext)
{
using namespace boost::python;
class_<Interface>("Interface", init<>())
.def("GetRawData", &Interface::GetRawData)
.def_readwrite("mrows", &Interface::mrows)
.def_readwrite("ncols", &Interface::ncols)
.def_readwrite("bNewData", &Interface::bNewData)
.add_property("zUpPatch1",
make_getter(&Interface::zUpPatch1, return_value_policy<reference_existing_object>()),
make_setter(&Interface::zUpPatch1, return_value_policy<reference_existing_object>()))
.add_property("zUpPatch2",
make_getter(&Interface::zUpPatch2, return_value_policy<reference_existing_object>()),
make_setter(&Interface::zUpPatch2, return_value_policy<reference_existing_object>()))
.add_property("zDownPatch1",
make_getter(&Interface::zDownPatch2, return_value_policy<reference_existing_object>()),
make_setter(&Interface::zDownPatch2, return_value_policy<reference_existing_object>()))
.add_property("zDownPatch2",
make_getter(&Interface::zDownPatch2, return_value_policy<reference_existing_object>()),
make_setter(&Interface::zDownPatch2, return_value_policy<reference_existing_object>()))
.add_property("bNewData",
make_getter(&Interface::bNewData, return_value_policy<reference_existing_object>()),
make_setter(&Interface::bNewData, return_value_policy<reference_existing_object>()))
;
}
以下是来自boost编译器的错误消息:
C:\...\.../data_members.hpp(64) : error C2440: '=' : cannot convert from
'const double [1000][5]' to double [1000][5]'
There is no context in wich this conversion is possible
C:\...\.../data_members.hpp(63) : while compiling class template member function
'void boost::python::detail::member<Data,Class>::operator ()(Class &,const double (&)) const'
with
[
Data=double [1000][5],
Class=Class
]
提前致谢!