Function with default parameters
Steven Schveighoffer
schveiguy at yahoo.com
Fri Sep 17 15:40:16 PDT 2010
On Fri, 17 Sep 2010 18:37:09 -0400, Mariusz Gliwiński
<alienballance at gmail.com> wrote:
> I just could promise I've seen in D2 something like in scripting
> languages:
>
> module test;
>
> void main (string[] args) {
> test(b = "test");
> }
>
> void test(string a = "a", string b = "b", string c = "c") {
> }
>
> Basically picking just right parameter while other have default. But now
> I can't find syntax anywhere. This code didn't worked, could you refresh
> my memory?
D parameters don't work this way. You cannot specify a parameter by name.
There are tricks you can use, such as structs with initializers, but the
result is probably not what you want.
-Steve
More information about the Digitalmars-d-learn
mailing list