WTF! new in class is static?!?!

Jonathan M Davis newsgroup.d at jmdavisprog.com
Fri Jun 8 18:18:27 UTC 2018


On Thursday, June 07, 2018 22:43:50 aliak via Digitalmars-d-learn wrote:
> On Thursday, 7 June 2018 at 21:32:54 UTC, Jonathan M Davis wrote:
> > struct S
> > {
> >
> >     int* ptr = new int(42);
> >
> > }
>
> Is that supposed to compile? -> https://run.dlang.io/is/SjUEOu
>
> Error: cannot use non-constant CTFE pointer in an initializer
> &[42][0]

Not necessarily. It's the pointer equivalent of what the OP did with a
mutable class reference, and I was using it for demonstrative purposes. The
mutable class reference case didn't used to compile (it used to have to be
immutable). This example is just the logic of what happens if it's legal
with pointers too. If it hasn't been changed to be legal with pointers like
it has been with classes, then that's arguably a good thing.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list