Re: Silly struct behaviour

2017-07-14 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-07-13 20:07, JN wrote: 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}));

Re: Silly struct behaviour

2017-07-13 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 13, 2017 at 06:48:27PM +, JN via Digitalmars-d-learn wrote: > On Thursday, 13 July 2017 at 18:09:46 UTC, H. S. Teoh wrote: > > > > It's not quite so simple. Consider for example: > > > > struct Foo { int bar; } > > struct Oof { int bar; } > > > > void process(Foo

Re: Silly struct behaviour

2017-07-13 Thread JN via Digitalmars-d-learn
On Thursday, 13 July 2017 at 18:09:46 UTC, H. S. Teoh wrote: It's not quite so simple. Consider for example: struct Foo { int bar; } struct Oof { int bar; } void process(Foo foo) { } void process(Oof oof) { formatDisk(); } void main() {

Re: Silly struct behaviour

2017-07-13 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 13 July 2017 at 18:45:45 UTC, JN wrote: I know that's a wrong syntax, I was just showing an example. Yes, here it will work, but if you want to initialize only some fields (poor man's keyword arguments), you can't use the default constructor. easily fixable by using

Re: Silly struct behaviour

2017-07-13 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 13, 2017 at 06:07:31PM +, JN via Digitalmars-d-learn wrote: > Consider: > > struct Foo > { > int bar; > } > > void processFoo(Foo foo) > { > } > > void main() > { > Foo f = {bar: 5}; > processFoo(f);// ok > processFoo(Foo(5)); //

Silly struct behaviour

2017-07-13 Thread JN via Digitalmars-d-learn
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 }