Reputation: 31
I need to embed Python in C++ and I am confused of the class type exchange between Python and C++.
If I have a C++ class as follow:
class MyClass{
public:
void printMessage();
private:
int m_iVal;
std::string m_sVal;
};
How can I convert the instance of MyClass into PyObject? Thank you very much!
Upvotes: 1
Views: 882
Reputation: 2230
If you use the model named ctypes, you can't convert c++ class type to PyObject type, but you can convert c++ structure type to PyObject type which based on a python class named Structure in ctypes model. More
see 15.17.1.10. Structures and unions.
And there is another way to embed Python use C++, you should use this line #include <Python.h>
in your c++ program.More
Upvotes: 1