How to handle C++ return type std::vector in Python ctypes?

前端 未结 3 1963
半阙折子戏
半阙折子戏 2020-12-03 03:54

I cannot find how ctypes will bridge the gap between std::vector and Python; no where on the internet is the combination mentioned. Is this bad practice, does i

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 04:15

    Basically, returning a C++ object from a dynamically loaded library is not a good idea. To use the C++ vector in Python code, you must teach Python to deal with C++ objects (and this includes binary representation of the objects which can change with new version of a C++ compiler or STL).

    ctypes allows you to interact with a library using C types. Not C++.

    Maybe the problem is solvable via boost::python, but it looks more reliable to use plain C for the interaction.

提交回复
热议问题