2

我正在使用 boost python 来实现 C++ 和 Python 之间的互操作性。我在 c++ 中有枚举和结构,并且在 c++ 中有可以将这些结构作为参数的函数。我可以通过使用 boost python 在 python 中访问这个函数,但我不知道如何在 python 中将结构作为参数发送。Set 是 c++ 中的函数,可以将结构作为参数获取。所以在 python 中,我如何将这个结构作为参数发送。我能够在 python 中获得此功能,但无法将发送结构作为参数发送。谢谢您的帮助。

c++中的结构如下:

enum days
{
  friday,
  saturday
};
struct example
 {
    days m_day;
    std: string m_value;
 };

Class Base
 {
   public:
   void Set(example& Result) = 0;
  }
class Derived
{
  public:
  void Set(example& Result) 
  {
    Result.m_day = friday;
   }
4

1 回答 1

2

您必须像这样公开结构示例,然后在 python 中创建此结构的变量并将此变量作为参数发送。

Class_<example> (“example”)
.def_readwrite(“m_day” , & example:: day)
.def_readwrite(“m_value” , & example:: m_value)
;

希望这会有所帮助..

于 2013-11-14T17:58:43.990 回答