distinguish between classes and structures

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Mon Dec 15 07:47:33 PST 2008


Weed wrote:
> In C++, we had the problem - "slicing" objects.
> In D this problem is solved inability to inherit from structs.
> Without inheritance of structs many things are not possible, compared 
> with C++.
> Why, instead of the complete inability to inherit, just do not make 
> impossible to up casting struct type by value.
> 
> like this:
> 
> struct s1 {}
> struct s2 : s1 {}
> 
> s1 base;
> s2 derr;
> 
> s1* base_ptr = &derr; // ok
> s1 val = derr; // error

This is why:
   s1 val2 = *base_ptr; // error

(And disallowing '*ptr' on struct pointers is not likely to find much 
support)


More information about the Digitalmars-d-learn mailing list