Silly struct behaviour

JN via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 13 11:07:31 PDT 2017


Consider:

struct Foo
{
	int bar;
}

void processFoo(Foo foo)
{
}

void main()
{
	Foo f = {bar: 5};
	processFoo(f);                // ok
	processFoo(Foo(5));           // ok
	processFoo({bar: 5});         // fail
	processFoo(Foo({bar: 5}));    // fail
}


Whyyyy D? It makes no sense, the compiler knows what is the type 
of the first processFoo arg anyway...


More information about the Digitalmars-d-learn mailing list