this(T...) not called in struct constructor

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Sep 18 06:18:18 PDT 2013


On Wed, Sep 18, 2013 at 10:12:04AM +0200, monarch_dodra wrote:
> On Wednesday, 18 September 2013 at 05:28:41 UTC, Timothee Cour
> wrote:
> >This may have been discussed before, but I'm not sure whether this is
> >a bug or not. In any case it's a bit confusing.
> >
> >struct Foo2{
> >  this(T...)(T args){
> >    assert(0);
> >  }
> >}
> >
> >void main(){
> >  auto a2=Foo2();//doesn't call assert(0) (ie this(T...) not
> >called)
> >}
> 
> There is no "argument-less constructor" in D. "Struct()" is just
> shorthand for "Struct.init" (bar a few exceptional exceptions:
> @disabled this() and static opCall).
> 
> AFAIK, D decided to not have "default" constructors,
[...]

Note that this only applies to structs. Classes have default ctors.


T

-- 
Programming is not just an act of telling a computer what to do: it is
also an act of telling other programmers what you wished the computer to
do. Both are important, and the latter deserves care. -- Andrew Morton


More information about the Digitalmars-d-learn mailing list