Reputation: 583
I have a C++ program:
class X
{
private:
int a;
public:
int func(char *str);
};
Now I want to call the function func in my Python program. How can I do it?
I have successfully called C functions from my Python program using ctypes. However I can't seem to figure out how to call functions defined inside C++ objects.
I have already worked with ctypes, so I would like to figure out how to accomplishing it that way. However I'm open to other techniques. Also my project puts a constarint that I am not supposed to use wrapper function in my C++ program.
Upvotes: 0
Views: 164
Reputation: 612794
You tagged the question ctypes, but you cannot instantiate a C++ object directly from ctypes. You can wrap the C++ object in a C interface and then use ctypes. Or you could write a Python extension module which could include C++ code.
Upvotes: 1
Reputation: 646
try http://swig.org/ years ago i wrapped some c/c++ code to use them in wxPython with swig. i cannot remember too much details but i think swig is easy to use.
Hope that helps.
Upvotes: 0