I made some bindings from my C++ app for python.
The problem is that I use pointers to members (It’s for computing shortest path and giving the property to minimize as parameter).
This is the C++ signature:
std::vector<Path> martins(int start, int dest, MultimodalGraph & g, float Edge::*)
This is what I did (from what I understood in the doc):
%constant float Edge::* distance = &Edge::distance;
This is how I call my function from python:
foo.martins(0, 1000, g, foo.distance)
And this is the error I get:
NotImplementedError: Wrong number of arguments for overloaded function 'martins'.
Possible C/C++ prototypes are:
martins(int,int,MultimodalGraph &,float Edge::*)
I have an overloaded method that uses a default 4th paramaters, and it works perfectly.
So is it possible to use pointers to members with swig? If yes, what’s the trick? If no, what would be the most elegant way to work arround?
Thank you for your help!
UPDATE: if someone knows if Boost::python does it for sure, I’ll switch to it.
Don’t know about SWIG, but in boost::python you can write a wrapper:
And in python you would:
Since in Python floats are immutable, you can’t actually pass one to a method and expect the method to change the float value, so we adapt the code to return a tuple of values instead.