Why can't structs be derived from?

Steven Schveighoffer schveiguy at yahoo.com
Tue Mar 15 12:06:57 PDT 2011


On Tue, 15 Mar 2011 14:54:13 -0400, Jens <jne at somewhere.org> wrote:

> I didn't ask how to do composition in D. I asked why composition cannot
> be done via derivation, i.e., the reasoning behind the language design
> choice. A design faux paus IMO.

Because composition by inheritance can be *completely* implemented using  
alias this -- a feature that also provides other niceties.  Why provide  
another mechanism to do the exact same thing, just because you are used to  
it?

Note that "inheritance" is actually done exactly this way in C++, by  
putting the derived type at the front of the "derived" type, and aliasing  
all the methods/fields into the derived namespace.

Show me what composition by derivation provides that alias this does not.

-Steve


More information about the Digitalmars-d mailing list