On 09/08/2009 11:30 PM, Jean-Sébastien Guay wrote:

If I just add .def("getA", &B::getA, some_return_policy) to my class_ wrapper, on compile it will complain that it doesn't know which version of B::getA() I want. Up until now the way I wrapped this was to make a trivial wrapper function:

A* (B::*B_getA1)() = &B::getA;

This is not a wrapper function, but an alias. You create a new variable 'B_getA1', and make this point to B::getA (the non-const version). This works, since by means of the variable type you disambiguate, so using that in the call to def() works unambiguously.


and then used .def("getA", B_getA1, some_return_policy). But as I wrap many classes, I wind up with lost of these trivial wrappers at the top of my source files, they're hard to read when skimming and just plain look bad. Is there some template or preprocessor magic I could use to generate these automatically, or even better, to allow me to specify in the .def() which version I want?

You may disambiguate by using a cast inside .def(), such as

  .def("getA", (A*(B::*)())B::getA);

 Whether that's actually more readable is arguable, however.


Regards,
        Stefan


--

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

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to