1

Let's say I have a module where I define a Animal class in Python. It has some simple attributes like height and weight. And let's say it has a couple simple member functions like getHeight() and makeSound().

I also have a non-member function returnAnimal() that simply returns a new instance of an Animal

I've embedded the python interpreter in a C++ function using the Python C API. From here I know how to run python functions that have return types like int, char*, etc.

But how can I accept functions with user defined types, such as my Animal class?

  • Your question as it is written is rather broad (_which_ C API/backend are you referring to?); given that others have asked similar questions, you may wish to consult those threads to gather ideas on how you might want to approach this, and then you may ask more specific questions. – metatoaster Aug 15 '19 at 23:55
  • 1
    Please check out: [Using Python obects in C++](https://stackoverflow.com/questions/37577676/using-python-objects-in-c), [Passing python objects as arguments to C/C++ function using ctypes](https://stackoverflow.com/questions/11213072/passing-python-objects-as-arguments-to-c-c-function-using-ctypes), and [Passing a Python class instance into a C++ function](https://stackoverflow.com/questions/23440197/passing-a-python-class-instance-into-a-c-function) – metatoaster Aug 15 '19 at 23:55

0 Answers0