Default argument values
Adam Ruppe
destructionator at gmail.com
Thu May 20 14:23:04 PDT 2010
On 5/20/10, bearophile <bearophileHUGS at lycos.com> wrote:
> A default argument may be an arbitrary expression.
What I do in code where I want this kind of behaviour is something like this:
void func(Whatever* options = null) {
if(options is null)
options = Whatever(default blah blah);
}
(substitute null for any invalid amount for the parameter. I recently
did some timezone functions that used int.min as the default offset,
meaning load it from the global.)
If I want to change the Whatever default, I change it there and it
still works out. Nothing fancy required.
On 5/20/10, Nick Sabalausky <a at a.a> wrote:
> I dunno, a caller might rely on a default value being what it was when they
> had compiled it.
Eh, if you leave the argument off the list, you're saying "I don't
really care what this is", so you shouldn't worry about changes... key
word being "shouldn't". I know I've broken this rule before, so having
to recompile at least would be nice, like you say.
More information about the Digitalmars-d
mailing list