new principle of division between structures and classes

Weed resume755 at mail.ru
Thu Jan 15 22:02:20 PST 2009


Weed пишет:
> Denis Koroskin пишет:
>> On Sun, 11 Jan 2009 05:04:11 +0300, Weed <resume755 at mail.ru> wrote:
>>
>>> Bill Baxter пишет:
>>>> 2009/1/11 Weed <resume755 at mail.ru>:
>>>>> Bill Baxter пишет:
>>>>>
>>>>>> But since classes can be polymorphic, value copying gets you into
>>>>>> slicing problems.  That's why value copying is disabled to begin with.
>>>>>>  So disabling value copies is a good thing.
>>>>> It is not always a good thing.
>>>> Yeh, I just mean there is some merit in disabling value copies.  But I
>>>> don't rule out the possibility that there may be an even better way
>>>> that banning them altogether.
>>>>
>>>>> I propose to prohibit only the copying by value of the base type to
>>>>> derivative type
>>>> Ok, this is key.  How do you propose to do this?  In general it
>>>> requires a runtime check, I think.
>>>> And I think you need to say that you prohibit copying unless
>>>> typeA==typeB exactly.  If you allow copying either way between base
>>>> and derived you are asking for trouble.
>>>>
>>>> But still given
>>>>   Base x = get_one();
>>>>   Base y = get_another();
>>>>   *x = *y; // presumed value copy syntax
>>>>
>>>> you have no way in general to know that x and y are really both a Base
>>>> at compile time.  So you must have a run-time check there.  Perhaps it
>>>> could be omitted for -release builds, though.
>>> It can lead to a difficult and non-reproduceable errors than old
>>> C++-style splitting.
>>>
>>> It is possible to try to prohibit assignment of the dereferenced
>>> pointers? Simply to prohibit assignment too it is possible, essentially
>>> it changes nothing.
>>>
>> Err.. I don't get what you say. The *x = *y is just one of the possible
>> syntaxes, nothing else.
>>
> 
> (I have incorrectly expressed)
> 
> If dereferencing was not used in lvalue or rvalue and is both a classes
> by value it is possible to assignment, except cases when the base type
> to the derivative is assigned.
> 
> Example:
> 
> class C {}
> class C2 : C {}
> 
> C c();
> C2 c2();
> 
> C* c_p = &c;
> C2* c2_p = &c2;
> 
> c = c2; // ok
> c2 = c; // err
> *c_p = *c2_p; // err
> *c2_p = *c_p; // err
> c2 = *c2_p; // err
> 
> and:
> c = c2 + *c2_p; // ok
> 

And any remark on the sentence?..



More information about the Digitalmars-d mailing list