Question

I am using boost python for interoperability between C++ and the Python . i have enum and structure in c++ and have function in c++ that can take these structure as a parameter. and i am able to access this function in python by using boost python but i don't know how to send structure as parameter in python. Set is function in c++ that can get structure as parameter.so in python how can i send this structure as a parameter . i am able to get this function in python but not able to send send structure as parameter. thanks for the help.

structure in c++ is as follow:

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;
   }
Était-ce utile?

La solution

You have to expose structure example like this and then create a variable of this structure in python and send this variable as argument.

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

Hope this will help..

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top