Pretty please: Named arguments

Stewart Gordon smjg_1998 at yahoo.com
Fri Mar 11 11:01:03 PST 2011


On 09/03/2011 12:22, Gareth Charnock wrote:
<snip>
> Which meant I had to look up what the default values of pos,size and style where even
> though I was happy with those default values. The more arguments the more of a pain this
> setup is without named arguments. Contrast to a hypothetical C++ syntax:
>
> new wxFrame(a_parent,wxANY,"Hello world",name = "My Custom name str")
<snip>

This isn't hypothetical C++ syntax, it's perfectly legal C++ syntax.  It is equivalent to

     name = "My Custom Name str", new wxFrame(a_parent, wxANY, "Hello world", name)

Struct and array initialisers use a colon, not an equals sign, and if we add named 
arguments they would need to do the same to avoid changing the meaning of existing code. 
You may be just illustrating the concept and not proposing this as the actual syntax to 
add to C++ or D, but being careful now will help you to get used to the feature when/if it 
arrives.

Stewart.


More information about the Digitalmars-d mailing list