[C++-sig] Providing a default value for a pointer argument

Roman Yakovenko roman.yakovenko at gmail.com
Wed Mar 22 15:41:46 CET 2006


On 3/22/06, Ralf W. Grosse-Kunstleve <rwgk at yahoo.com> wrote:
> --- Matthias Baas <baas at ira.uka.de> wrote:
> > int ptrarg(Spam* s=0)
> > {
> >    if (s==0)
> >      return 0;
> >    else
> >      return 1;
> > }
> >
> > BOOST_PYTHON_MODULE(mod)
> > {
> >    class_<Spam>("Spam", init<>());
> >
> >    def("ptrarg", ptrarg, (arg("s")=0));
> > }
>
> You are missing BOOST_PYTHON_FUNCTION_OVERLOADS for ptrarg:
>
>   http://www.boost.org/libs/python/doc/v2/overloads.html
>
> I am not sure if the =0 works for pointers, but the overloads trick is
> definitely required.

What should happen if I have an other function that takes as argument
an other type?

int ptrarg(Spam* s=0) {...}
int ptrarg(int){...}
int ptrarg(int, Spam*){...}
int ptrarg(Spam*, int){...}

> Cheers,
>         Ralf

Thanks

--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/



More information about the Cplusplus-sig mailing list