Explicit default constructor for structs

Remo remo4d at gmail.com
Thu Apr 10 08:21:27 PDT 2014


On Thursday, 10 April 2014 at 11:39:16 UTC, Andrej Mitrovic wrote:
> On 4/9/14, Brian Schott <briancschott at gmail.com> wrote:
>> Really? What does this program print using a current version of
>> DMD?
>>
>> import std.stdio;
>>
>> struct SomeStruct
>> {
>> 	this(int i = 10)
>> 	{
>> 		this.i = i;
>> 	}
>> 	int i;
>> }
>>
>> void main(string[] args)
>> {
>> 	auto s = SomeStruct();
>> 	writeln("s.i = ", s.i);
>> }
>
> This is a current bug that is going to be fixed:
> https://github.com/D-Programming-Language/dmd/pull/1397


Please do not forget about C++ porting problems that are related 
to this.
The code from C++ should compile and work as expected or does not 
compile at all and give meaningful error message.
Right now it compiles but does not work at all.
This struct constructor problem is one of the ground why I have 
stopped porting code to D.
I hope there will be proper solution soon.




More information about the Digitalmars-d mailing list