Quick question about new semantics

monarch_dodra monarchdodra at gmail.com
Fri Sep 14 11:27:56 PDT 2012


I have a struct, which defines a constructor that takes an 
argument.

Now, I'd like to new this object, to it's default T.init value 
(eg call new, but now constructors):

--------
struct S
{
     this(int);
}

void main()
{
     auto p1 = new S;
     auto p2 = new S();
}
--------
main.d(8): Error: constructor main.S.this (int) is not callable 
using argument types ()
main.d(8): Error: expected 1 function arguments, not 0
main.d(9): Error: constructor main.S.this (int) is not callable 
using argument types ()
main.d(9): Error: expected 1 function arguments, not 0
--------
Is this a bug? If "auto a = S();" is legal, how can "auto p = new 
S();" not be?


More information about the Digitalmars-d-learn mailing list