new principle of division between structures and classes
Bill Baxter
wbaxter at gmail.com
Sat Jan 10 16:19:16 PST 2009
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.
>> And that's also the problem with putting scope'd things inside another
>> class or an array. Since they don't have value semantics,
>
> Yes, this is what I mean
So assuming you had this, the important question is what would you do with it?
You still have the problem that the current system works pretty well.
And has a lot of history. So you need a very compelling use case to
convince Walter that something should change.
--bb
More information about the Digitalmars-d
mailing list