Scope & Structs
Nick Treleaven
nick at geany.org
Sat Oct 12 13:08:03 UTC 2024
On Saturday, 12 October 2024 at 12:10:17 UTC, Salih Dincer wrote:
> On Saturday, 12 October 2024 at 12:02:04 UTC, Salih Dincer
> wrote:
>> ... even if I call the structure with the new operator. But if
>> I stop using classes, scope doesn't work properly!
Declaring a `scope SomeClass` initialized with `new` is a special
case to allocate on the stack:
https://dlang.org/spec/attribute.html#scope-class-var
> Edit: It seems like scope is ineffective in structures. In
> fact, if there is the new operator, it is as if scope does not
> exist, and if it is construct without the new operator, it is
> as if scope does exist; is this normal?
If you want stack allocation of structs, why use `new`?
More information about the Digitalmars-d-learn
mailing list