Classes on stack

dd dd at dax.moe
Thu Sep 1 12:51:28 UTC 2022


On Thursday, 1 September 2022 at 09:13:56 UTC, Redwan wrote:
> Hi all
> I'm new to D from c, cpp and Rust.
>
> this language made me surprised because of its features and 
> syntax and etc.
>
> but I shocked when I found that classes must be created only on 
> stack! Is this nightmare real? why???
> I want declare classes and create instance of them on stack and 
> nicely use them. why I must put them on heap??
> structs does not support inheritance and I don't want to use 
> them. please tell me that is not true or give me some other 
> ways. I don't want define objects always on heap. don't let me 
> go back on cpp :( tnx!

I think something like std.typecons.scoped 
(https://dlang.org/phobos/std_typecons.html#scoped) does 
something like this, I think.


More information about the Digitalmars-d mailing list