Why can't structs be derived from?

Steven Wawryk stevenw at acres.com.au
Tue Mar 15 17:24:07 PDT 2011


On 16/03/11 10:30, Steven Wawryk wrote:
> On 16/03/11 04:59, Andrei Alexandrescu wrote:
>> The reason for the allegedly ugly syntax is that it's considerably more
>> general. It is often the case that a struct defines an entity that is
>> implicitly convertible to another entity - could be an rvalue vs.
>> lvalue, a class vs. another struct vs. a primitive type, could need a
>> run-time operation etc. Inheritance would offer at best few of these
>> amenities, whereas 'alias this' offers all with a simple syntax.
>
> More general?! How would you express the equivalent of
> static_cast<slist_node<T> >(base) in the original sample code?

Sorry, I meant static_cast<slist_node<T> *>(base_ptr).


More information about the Digitalmars-d mailing list