Default initialization of struct

simendsjo simendsjo at gmail.com
Wed Feb 13 02:43:42 PST 2013


On Wednesday, 13 February 2013 at 08:49:41 UTC, Daniel Kozak 
wrote:
> Hi all,
>
> I play with structs and UDAs today, and I found out some 
> limitation:
>
> struct Entity
> {
> 	string name;
> }
>
> void main(string[] args)
> {
>   Entity entity = {name : "Name"}; // static initialization by 
> name
>   auto entity2 = Entity(); // default initialization
>   auto entity3 = {name : "Name"}; // should be nice to have
>   auto entity4 = Entity(name : "Name"); // and this would be 
> useful too. Eg.: for UDAs @Entity(name : "EntityName")
> }


entity3: What should the compiler do? Guess the type as long as 
it has a constructor with "name"?
entity4: You're talking about static opCall and named parameters. 
I'm pretty sure named parameters have been rejected as parameter 
names would be part of the public interface for functions.


More information about the Digitalmars-d mailing list