How to do "C++ classes"?

Ferhat Kurtulmuş aferust at gmail.com
Mon Sep 20 16:00:12 UTC 2021


On Monday, 20 September 2021 at 15:56:44 UTC, Ferhat Kurtulmuş 
wrote:
> On Monday, 20 September 2021 at 15:45:08 UTC, Adam D Ruppe 
> wrote:
>> On Monday, 20 September 2021 at 15:35:02 UTC, Ferhat Kurtulmuş 
>> wrote:
>>> I thought it's stack-allocated and scoped.
>>
>> It is.
>>
>>> But when I try to return a class instance from a function, it 
>>> still works?
>>
>> dmd only makes that an error if you specify `@safe` and i 
>> think `-dip1000`. Try adding one or both of those and 
>> recompiling and see what happens.
>>
>> Note that even if the compiler doesn't error on it, it is 
>> undefined behavior to return the stack reference so be sure to 
>> treat it right.
>
> That is what I thought too. I only tried this on the online 
> compiler. Thank you. Have a great day or night captain.

I also think this is a dirty corner of the complier since it must 
raise an error for scoped instances of classes.



More information about the Digitalmars-d-learn mailing list