digitalmars.D - structs, classes, interfaces - Part II, Problem
- Martin Hinsch (24/24) Sep 01 2007 As has been explained by several people several times there is a good re...
As has been explained by several people several times there is a good reasons for keeping structs and classes separate: - RTTI (in the general sense, includes vtables and such) makes classes byte-incompatible with the respective sequence of plain types. Classes with RTTI therefore can't be (easily) used as "masks" for plain sequences of bytes. There are also good reasons to exclusively use reference semantics with classes: - Slicing, that is the loss of information when assigning a subclass object to a superlass object is avoided. - Consistent (runtime) polymorphism, i.e. since class objects are always references method calls can be polymorphic per default (which would be impossible in C++). The (IMHO quite high) cost for solving these problems is the existence of two relatively similar but largely incompatible concepts in the language. -- Martin Hinsch m.hinsch rug.nl +31 50 363 8097 CEES Centre for Ecological and Evolutionary Studies Biologisch Centrum Kerklaan 30 Postbus 14 9750 AA Haren
Sep 01 2007