struct and default constructor

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Fri Oct 10 23:09:16 PDT 2014


On Friday, October 10, 2014 22:49:13 Walter Bright via Digitalmars-d wrote:
> On 10/10/2014 9:43 PM, Dicebot wrote:
> > There is ER somewhere in bugzilla AFAIR about allowing CTFE-only struct
> > default constructors.
>
> Note that you can do (as pointed out upthread):
>
>     struct S {
>          int x = 7;
>          string s = "hello";
>     }
>
> which then has default initialization. Of course, CTFE will work on those
> rvalues.

The only reason that I can think of to have default constructors for filling
in the member variables during CTFE would be if you wanted to calculate some
of the values based on other values, and while that might be nice upon
occasion, I don't think that not having it is much of a loss.

- Jonathan M Davis



More information about the Digitalmars-d mailing list