地图的矢量(结构的。。无路

2024-04-23 17:02:26 发布

您现在位置:Python中文网/ 问答频道 /正文

尝试公开具有以下类型的映射向量(键为字符串,值为结构对象):

// boost includes ..

struct MyStruct {
  double a;
  vector<double> vec;
  bool operator==(const MyStruct& other) {return false;}
  bool operator!=(const MyStruct& other) {return true;}
};

typedef map<string, MyStruct>      MyMap;

typedef vector<MyStruct>           MyVec;
typedef vector<MyMap>              MyVec2;

BOOST_PYTHON_MODULE(_axstatistics)
{

    py::class_<MyStruct>("MyStruct")
        .def_readwrite("a", &MyStruct::a)
        .def_readwrite("vec", &MyStruct::vec)
        ;

    py::class_<MyMap>("MyMap")
        .def(map_indexing_suite<MyMap>());

    py::class_<MyVec>("MyVec")
        .def(vector_indexing_suite<MyVec>());

// uncomment and boum
//    py::class_<MyVec2>("MyVec2")
//        .def(vector_indexing_suite<MyVec2>());

}

这适用于MyVec,但不适用于MyVec2,我收到一个几乎无法读取的编译错误

有人对这种模式有想法或经验吗

提前支付Thx


Tags: pydefoperatorclasssuitebooldoublevector