boost :: python :: list获得值段错误

时间:2018-09-16 14:41:12

标签: c++ boost-python

我写了一段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的值。如何解决?

0 个答案:

没有答案