structure inheritance and polymorphism
Paul Backus
snarwin at gmail.com
Mon Jan 4 01:28:33 UTC 2021
On Monday, 4 January 2021 at 01:06:20 UTC, zjh wrote:
> Can d be added with support for structure inheritance and
> polymorphism?
> I like D, but I don't like GC, so I can't use classes. I can
> only use betterC. But I want d to have c++ structure
> inheritance and polymorphism. In this way, I think the
> competition with c++, the odds are better.
You can use classes without the GC. You just have to allocate and
free them manually, either with malloc/free or something like
std.experimental.allocator. You may also find a smart-pointer
library like automem useful for this:
https://code.dlang.org/packages/automem
If you want to avoid the D runtime completely, you cannot use
"normal" D classes, but extern(C++) classes will still work.
If you absolutely must use structs, you can use "alias this" to
achieve something very similar to inheritance:
https://dlang.org/spec/class.html#alias-this
More information about the Digitalmars-d
mailing list