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

Roman Yakovenko roman.yakovenko at gmail.com
Wed Mar 22 16:14:57 CET 2006


On 3/22/06, Ralf W. Grosse-Kunstleve <rwgk at yahoo.com> wrote:
> --- Roman Yakovenko <roman.yakovenko at gmail.com> wrote:
> > int ptrarg(Spam* s=0) {...}
> > int ptrarg(int){...}
> > int ptrarg(int, Spam*){...}
> > int ptrarg(Spam*, int){...}
>
> You have to fiddle around with casts. It is not pretty, but does the trick.
> However, if it gets too complicated I prefer to use simple thin wrappers, e.g.:
>
> int ptrarg_spam_0() { return ptarg(); }
> int ptrarg_spam_1(Spam* s) { return ptrarg(s); }
> int ptrarg_int(int i) { return ptrarg(i); }
> int ptrarg_int_spam(int i, Spam* s) { return ptarg(i, s); }
> int ptrarg_int_spam(Spam* s, int i) { return ptarg(s, i); }
>
> def("ptarg", ptrarg_spam_0);
> def("ptarg", ptrarg_spam_1);
> def("ptarg", ptrarg_int);
> def("ptarg", ptrarg_int_spam);
> def("ptarg", ptrarg_spam_int);

Thanks. This is something I can understand. An other question:
boost.python have optional class, that we use for constructors ( init ) .
>From documentation I understand that I can not use optional for
regular "def"'s, right?

Except of "luck of time", is there is an other reason (==technical) for not
supporting optional on "def"'s


> Cheers,
>         Ralf

Thank you

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



More information about the Cplusplus-sig mailing list