On Friday, 20 February 2015 at 07:57:17 UTC, Tobias Pankrath wrote:
What's the reason behind this design?

class Super {}
class Sub : Super {}

void foo(Super[] sup) {}

void main() {
    Sub[] array;
foo(array); // error, cannot call foo(Super[]) with arguments (Sub[])
}

Just make the sup parameter const:

void foo(in Super[] sup) {}

http://dlang.org/arrays.html (end of the page):

A dynamic array T[] can be implicitly converted to one of the following:
const(U)[]
const(U[])
Where U is a base class of T.

The reson behind the design - I wonder about that also.

Reply via email to