Re: Why isn't field-wise constructor automatic for structs and not classes?

2016-01-02 Thread John Colvin via Digitalmars-d-learn
On Saturday, 2 January 2016 at 02:12:19 UTC, Shriramana Sharma wrote: If I have: struct TimeSpan { double start, end; } Then both the following automatically work: auto s = TimeSpan(); auto t = TimeSpan(1, 2); But if I make it a class (I need to) then I have to explicitly define a

Re: Why isn't field-wise constructor automatic for structs and not classes?

2016-01-02 Thread John Colvin via Digitalmars-d-learn
On Saturday, 2 January 2016 at 14:57:58 UTC, Shriramana Sharma wrote: John Colvin wrote: Strictly speaking you aren't calling a constructor there, you're writing a struct literal. Why do you say I'm not calling a constructor? https://dlang.org/spec/struct.html#struct-literal And that

Re: Why isn't field-wise constructor automatic for structs and not classes?

2016-01-02 Thread Shriramana Sharma via Digitalmars-d-learn
John Colvin wrote: > Strictly speaking you aren't calling a constructor there, you're > writing a struct literal. Why do you say I'm not calling a constructor? And that still doesn't answer the question of why can't we have an automatic field-wise constructor for classes... -- Shriramana

Re: Why isn't field-wise constructor automatic for structs and not classes?

2016-01-02 Thread rumbu via Digitalmars-d-learn
On Saturday, 2 January 2016 at 14:57:58 UTC, Shriramana Sharma wrote: John Colvin wrote: Strictly speaking you aren't calling a constructor there, you're writing a struct literal. Why do you say I'm not calling a constructor? A class constructor is written as: auto s = *new* Timespan(1,

Why isn't field-wise constructor automatic for structs and not classes?

2016-01-01 Thread Shriramana Sharma via Digitalmars-d-learn
If I have: struct TimeSpan { double start, end; } Then both the following automatically work: auto s = TimeSpan(); auto t = TimeSpan(1, 2); But if I make it a class (I need to) then I have to explicitly define a field-wise constructor else only a constructor with no args is automatically