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

Shriramana Sharma via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 1 18:12:19 PST 2016


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 
defined. Why can't the field-wise functionality be automatic for classes 
too?

-- 
Shriramana Sharma, Penguin #395953


More information about the Digitalmars-d-learn mailing list