no-argument constructor: is this a bug?

Timon Gehr timon.gehr at gmx.ch
Sun Jan 22 16:10:52 PST 2012


On 01/23/2012 12:51 AM, Caligo wrote:
> struct A(uint samples){
>
>    float[samples] _data = void;
>
>    this(float val = 0.0f){ fill(_data[], val); }
> }
>
>
>    auto a = A!8();
>
> a._data is filled with garbage instead of zeros because the
> no-argument constructor is called instead of the one that I've
> defined.

structs are always default-constructible, and, as a tie-breaker, a 
function definition that has the exact number of arguments is considered 
a better match one that has to supply default-arguments to match. You 
could use a static opCall to make auto a = A!8() work.


More information about the Digitalmars-d-learn mailing list