[C++-sig] Overloading & keyword args bug?

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Thu Jun 8 03:44:03 CEST 2006


--- Alex Mohr <amohr at pixar.com> wrote:
> #include <boost/python.hpp>
> #include <string>
> #include <cstdio>
> 
> using namespace boost::python;
> using std::string;
> 
> static void f1(string const &a1, int x, int y) {
>      printf("f1 with %s, %d, %d\n", a1.c_str(), x, y);
> }
> 
> static void f2(string const &a1, string const &a2, int x, int y) {
>      printf("f2 with %s, %s, %d, %d\n", a1.c_str(), a2.c_str(), x, y);
> }
> 
> BOOST_PYTHON_MODULE(overload_kw) {
>      def("f", f1, (arg("x")=3, arg("y")=4)); // ########
>      def("f", f2, (arg("x")=5, arg("y")=6)); // ########
> }

I am surprised any of your tests works.
AFAIK you need to make several changes:

BOOST_PYTHON_FUNCTION_OVERLOADS(f1_overloads, f1, 1, 3)
BOOST_PYTHON_FUNCTION_OVERLOADS(f2_overloads, f2, 2, 4)

you have to give your C++ functions default arguments.

you have to define all arg(), i.e something like

  def("f", f1, f1_overloads((arg("a1"), arg("x")=3, arg("y")=4)));

At least this is what I do all the time.


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Cplusplus-sig mailing list