Why can't structs be derived from?

Jens jne at somewhere.org
Tue Mar 15 10:29:37 PDT 2011


Jonathan M Davis wrote:
> On Tuesday 15 March 2011 06:25:13 Jens wrote:
>> It seems rather fundamental to be able to compose a new struct from a
>> given struct using inheritance. Why is this not allowed?
>>
>> struct slist_node
>> {
>>     slist_node* next;
>> };
>>
>> template <class T>
>> struct slist_node<T>: public slist_node
>> {
>>     T data;
>> };
>
> Classes are polymorphic. Structs are not.

OK, silly me. I used a wrong example. I really did want to know about 
non-polymorphic composition from structs via derivation. Sorry for the 
confusion.

struct point
{
    int x;
    int y;
};

struct point3d: point
{
    int z;
};




More information about the Digitalmars-d mailing list