我写了一段boost::python::list
的测试代码,但我得到了segment fault
#include <iostream>
#include <boost/python.hpp>
#include <boost/python/list.hpp>
#include <boost/python/extract.hpp>
using namespace std;
using namespace boost;
void test(const boost::python::list & action, int i);
void test(const boost::python::list & action, int i) {
cout << "step into here" << endl;
double a = boost::python::extract<double>(action[i]);
cout << a << endl;
}
int main() {
cout << "Hello World!" << endl;
boost::python::list action;
for (int i = 0; i < 10; i++) action.append(1.0);
// int n = boost::python::extract<double>(action.attr("__len__")());
// cout << n << endl;
test(action, 0);
return 0;
}
似乎段错误发生在
double a = boost::python::extract<double>(action[i]);
但是列表的长度为10,我想获取索引为0的值。如何解决?