在python中如何将结构作为参数发送

2024-05-14 00:41:10 发布

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

我使用PosithPython来处理C++和Python之间的互操作性。我在c++中有enum和structure,在c++中有可以将这些结构作为参数的函数。我可以通过使用boostpython在python中访问这个函数,但是我不知道如何在python中将结构作为参数发送。Set是c++中的函数,它可以将结构参数.so在python中,如何将此结构作为参数发送。我可以在python中获得这个函数,但不能将send结构作为参数发送。谢谢你的帮助。在

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;
   }

Tags: 函数参数exampleenumresultpublicdaysstructure
1条回答
网友
1楼 · 发布于 2024-05-14 00:41:10

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

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

希望这会有帮助。。在

相关问题 更多 >