Why structs and classes instanciations are made differently ?

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 24 08:41:33 PDT 2017


On 7/24/17 11:21 AM, Houdini wrote:
> Hello,
> 
> I am a C++ coder, and I am learning D (just reading a book, for now).
> 
> D is very similar to C++ (and also grabs godd ideas from Python), but I 
> have a naive question : why does Walter Bright chose to instanciate 
> classes like in Java ? And why is it different for structs ?

Because types with inheritance generally don't work right if you pass by 
value (i.e. the slicing problem).

structs don't support inheritance or virtual functions, so they can be 
safely passed by value.

-Steve


More information about the Digitalmars-d-learn mailing list