Classes or stucts :: Newbie

bearophile bearophileHUGS at lycos.com
Mon Dec 20 02:43:08 PST 2010


Nick Voronin:

> Here is where we diverge. Choosing struct vs class on criteria of their placement makes no sense to me. 

In D you use a class if you want inheritance or when you (often) need reference semantics, and you use a struct when you need a little value passed around by value or when you want a simple form of RAII or when you want to implement something manually (like using PIMPL), or when you want max performance (and you manage structs by pointer, you may even put a tag inside the stuct or the pointer and implement manually some kind of inheritance). With structs you have a literal syntax, postblits, in-place allocation, and you are free to use align() too.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list