[C++-sig] Convert C++ Class to exposed class and back

Stefan Seefeld seefeld at sympatico.ca
Tue Feb 12 15:07:22 CET 2008

Marcus Jannes wrote:
> Thank you, i think this is exactly what i need. Regarding your question why i want to use it in this way:
> It is because i want to convert Python function objects to C++ function pointers which get passed to a another function and this seems to be the way to do it. The boost.python FAQ (see: http://www.boost.org/libs/python/doc/v2/faq.html ) states that it isnt possible, unless i misunderstood it. So i am trying it in C API. Now i should be able to :-). If there is any better way to do it, i would be happy to know.

I think you misunderstood. The problem is not with the API, but with the 
underlying object model: As Dave notes in the FAQ, a (C, C++) function 
pointer is not an object, and thus has no state to carry around.
Unless your function takes not only a function pointer but also some 
closure argument (which would then carry that state), you are out of luck.

In contrast, if you do get to pass a closure argument, you can pass a 
python (callable) there, and then implement the function whose pointer 
you pass such that it simply invokes that callable.

In either case, the problem is the same, no matter whether you try to 
solve it with Python's C API or boost.python.



       ...ich hab' noch einen Koffer in Berlin...

More information about the Cplusplus-sig mailing list