grep
janderson
askme at me.com
Sat May 10 14:07:45 PDT 2008
Dee Girl wrote:
> janderson Wrote:
>
>> //ie
>> class A
>> {
>>
>> };
>>
>> class B : A
>> {
>>
>> };
>>
>> B[] b;
>> b ~= new B;
>> A[] a = b;
>> a ~= new A;
>> //b[1] Is not an A type (not a B type), but is essentially a reinterpret
>> A -> B.
>
> Your example compiles but it was so good if it did not. Modifiable arrays should never be covariant! Why did D make the same mistake that Java and Eiffel did? Newer languages should learn from the mistakes of the old languages. This is more than a bit disappointing. Dee Girl
I agree its not particularly good. Then again, if your using casting
for anything you should think twice about what your doing. I think the
reason for allowing A[] a = b; is polymorphism. The problem comes when
you append a new A. I think the solution would be to make A[] invariant
or const and enforce it by the compiler. That way you can't add
anything to B[] indirectly but can still pass it into functions that
take invariant A[].
More information about the Digitalmars-d
mailing list