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}));
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
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() {
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
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)); //
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
}