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

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Wed Mar 22 16:05:56 CET 2006


--- 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);

Cheers,
        Ralf


__________________________________________________
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