Struct with default ctor (Was: [dmd-beta] dmd 2.064 beta take 2)

Timothee Cour thelastmammoth at gmail.com
Fri May 17 17:07:28 PDT 2013


calling the default ctor static this() removes any such illusion.
----
struct A{
int[]x;
static this(){
x=[1,2,3];
}
}
void main(){
enum a=A.init;
static assert(a is A.init);
}
----
would work under this proposal.
What would be your alternate proposal that would still allow to initialize
x to [1,2,3] in the ctor?



On Fri, May 17, 2013 at 4:46 PM, Igor Stepanov <wazar.leollone at yahoo.com>wrote:

> When programmer see constructor, he think that it will be evaluated each
> time when he create a new object.
> This code will seem obvious for any C++ coder.
> And this coder will be deceived.
>
> If we'll add default constructor to structs, we'll must safe of illusion,
> that constructor is called any time when new object have been created. And
> reject all cases when we can't provide this illusion.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130517/a70d584a/attachment.html>


More information about the Digitalmars-d mailing list