首页 > 解决方案 > Python(使用 ctypes)中是否有处理 C++ 结构中包含的向量的功能?

问题描述

我正在使用 ctypes 编写一个 Python 类来模仿 c++ 结构,需要帮助解决 c++ 结构中定义的 std::vector<> 。

我已经通过在字段声明中将它们声明为 c_'type' 来处理在 uint64_t、double、long、char 等类型的 c++ 结构中声明的一般变量,但我无法找到解决向量的方法.

C++

struct TypeSample
{
 double _a
 double _b
 std::string toString() const
 {....}
}
struct Sample
{ 
    Sample()
    :
     _variableA(0),
     _variableB(1)
    {
    }
    uint64_t _variableA;
    double _variableB;
    std::vector<TypeSample> _variableC;
};

Python

from ctypes import *
class Sample(Structure):
  _fields_ = [('_variableA',c_unit64),
              ('_variableB',c_double),
              ('_variableC',?????????),
             ]

任何帮助将不胜感激,感谢您抽出宝贵的时间

标签: pythonc++ctypes

解决方案


推荐阅读