Are stack+heap classes possible in D?
FujiBar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jun 13 19:03:09 PDT 2015
On Sunday, 14 June 2015 at 01:31:25 UTC, Adam D. Ruppe wrote:
> On Sunday, 14 June 2015 at 00:52:20 UTC, FujiBar wrote:
>> I have read that in D structs are always allocated on the
>> stack while classes are always allocated on the heap.
>
> That's not true; it is a really common misconception.
>
> Putting a struct on the heap is trivial and built into the
> language: `S* s = new S();`
>
> Putting a class on the stack is a bit trickier, but the
> standard library provides a helper to do it:
> http://dlang.org/phobos/std_typecons.html#scoped follow the
> examples given there.
Thanks!
More information about the Digitalmars-d-learn
mailing list