0

I have a structure like this:

struct Person {
  std::string name;
  int age;
  std::string title;
  float income;
};

In the python side, I have a dict like this:

person = { 'name':'Alex', 
           'age':36, 
           'title':'programmer', 
           'income':13435.40
          }

Now I want to convert the Python dict to the C++ program by using ctypes. There is a stupid way to do this task is that we can write 4 c-style functions to set these four elements independently. How can we do this task in a single function, which can solve different data type (string, int, float)?

StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458
dodolong
  • 855
  • 2
  • 9
  • 14

1 Answers1

0

ctypes can't handle C++ on its own.

SWIG can though this is equivalent to writing a C wrapper for the C++ code. It requires building native code.

ephemient
  • 198,619
  • 38
  • 280
  • 391