Classes on stack
Guillaume Piolat
first.last at spam.org
Thu Sep 1 12:19:42 UTC 2022
On Thursday, 1 September 2022 at 12:08:05 UTC, Redwan wrote:
>
> I need inheritance and other OOP concepts and template
> features. does D's struct support them? as I found, No.
There are ways to put classes on the stack (std.typecons.scoped,
emplace()...), but not completely polymorphic classes.
In C++, polymorphic dynamic-dispatch objects are not value types
either, you need the concrete type to put them on stack or risk
slicing. They would typically be on the heap with `new` /
`unique_ptr`.
So it's really the same constraints, if you have a capped maximum
of what the child class will be, you can also emplace in a byte
array on the stack any instance of the hiearachy.
More information about the Digitalmars-d
mailing list