this() in struct

Maxim Fomin maxim at maxim-fomin.ru
Tue Oct 9 10:59:24 PDT 2012


On Tuesday, 9 October 2012 at 17:32:35 UTC, Zhenya wrote:
> On Tuesday, 9 October 2012 at 17:21:47 UTC, Zhenya wrote:
>> Hi!
>> I'm sorry,maybe this topic already was discussed,but could 
>> anybody explain me
>> why default constructor was disallowed in structs?
>
> And if I have to do some initialization of data members,what is 
> the way to do it?

TDPL, the book by Andrei Alexandrescu, says that it was done for 
having compile time known default value for structure types which 
is T.init in general. For classes T.init is null so there is no 
problem. Assumption here is that statically known T.init and 
default constructor cannot coexist, however there are discussion 
in this forum that this issue may be reconsidered.

Absence of default structure constructors is a piece of the 
puzzle which is creation of D structures and consists of 
structure constructors, static/object opCall methods, struct 
literals together with static initialization. You may use any of 
this method for initialization, the problem is IMHO in their 
contradiction and priority.


More information about the Digitalmars-d-learn mailing list