[C++-sig] Re: Passing default argument

Nikolay Mladenov nickm at sitius.com
Mon Nov 3 16:02:52 CET 2003


You can do something else instead:

BOOST_PYTHON_MODULE(overload)
{
    class_<A>("A")
        .def("F",&A::f, (arg("a")=2,arg("b")=4,arg("c")=10,arg("d")=4)
))
    ;
}


"Goudar Basavaraj (IFIN DC SMS)" wrote:
> 
> Hi,
> 
>         I am facing a problem in passing default parameters to this program.
> 
> class A
> {
>         public:
>         A(){}
>         void f(int a=2,int b=4,int c=10,int d=4)
>         {
>                 printf("HI am here\n");
>         }
> };
> BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(F1,A::f,0,4)
> 
> BOOST_PYTHON_MODULE(overload)
> {
>     class_<A>("A")
>         .def("F",&A::f,F1(args("a","b","c","d")))
>     ;
> }
> 
>         I call the overloaded method from python by passing
>         >>>name=overload.A()
>         >>>name.F(a=0)  //This works fine
>         >>>name.F(a=0,b=1)   //This works fine
>         >>>name.F(b=1)     //Fails.
>                  bad argument type for built in operation
> 
>         I am not able to figure out whether this is the property of boost or
> I have to do something else.
> 
>         Please let me know................
> 
> Thanks & Regards,
> Basavaraj





More information about the Cplusplus-sig mailing list