Pretty please: Named arguments

Andrej Mitrovic andrej.mitrovich at gmail.com
Mon Feb 28 05:15:02 PST 2011


On 2/28/11, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
> This syntax already means something in D:
>
> string action;
> int times;
> foo(action = "dofoo", times = 100); // set action to "dofoo" and times to
> 100 and pass those to the function.
>
> -Steve
>

Except that doesn't do what you'd expect it to do:
void foo(ref int time) { }
void main()
{
    int times;
    foo(times = 100); // set times to 100 and pass to the function.
}

Error: function test.foo (ref int time) is not callable using argument
types (int)
Error: times = 100 is not an lvalue


More information about the Digitalmars-d mailing list