3 ms·
That would be nice in principle, but where do you expect the error to be thrown in the example above? I don't know of any language which tries to automatically
by tsimionescu 7y ago
That would be nice in principle, but where do you expect the error to be thrown in the example above?
I don't know of any language which tries to automatically deduce whether a variable is used in a read-only manner or not, and base covariance on this deduction.
Even C++, which allows you to explicitly annotate an array to declare that it is read-only (const vector<base*> ) doesn't allow you to pass an array of derived elements instead, so I assume there is some difficulty in implementing these checks and ensuring correctness.