Are D classes proper reference types?

kinke noone at nowhere.com
Thu Jun 24 07:28:56 UTC 2021


On Thursday, 24 June 2021 at 06:50:44 UTC, Ola Fosheim Grøstad 
wrote:
> [...]

Yes, class *refs* are always pointers. *scope* classes are 
deprecated (I don't think I've ever seen one); with `scope c = 
new Object`, you can have the compiler allocate a class 
*instance* on the stack for you, but `c` is still a *ref*. 
`emplace` doesn't allocate, you have to pass the memory 
explicitly. A class *instance* can also live in the static data 
segment (`static immutable myStaticObject = new Object;`); 
`extern(C++)` class instances can also live on the C++ heap/stack 
etc. etc.


More information about the Digitalmars-d-learn mailing list