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.
-
Who thinks this is "not a real question"? Why?Karl Knechtel– Karl Knechtel2012年04月11日 07:51:43 +00:00Commented Apr 11, 2012 at 7:51
4 Answers 4
Check out Boost::Python.
2 Comments
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.
4 Comments
An alternative to Boost.Python is SWIG.
Comments
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.