distinguish between classes and structures

Weed resume755 at mail.ru
Mon Dec 15 18:46:21 PST 2008


Frits van Bommel пишет:
> 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

I do not understand that it is wrong?

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


More information about the Digitalmars-d-learn mailing list