No polymorphism?
Dgame via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jul 24 10:29:55 PDT 2017
I may be just tired, but could somebody explain this behaviour to
me? It seems odd to me:
----
interface I
{
}
class S : I
{
}
void test1(I[])
{
}
void test2(I)
{
}
void main()
{
test1([new S()]); // Works
test2(new S()); // Works
I i = new S();
test2(i); // Works
S s = new S();
test2(s); // Works
I[] si = [new S()];
test1(si); // Works
S[] ss = [new S()];
test1(ss); // Fails
}
----
Compiler output: test.d(32): Error: function test1 (I[] _param_0)
is not callable using argument types (S[])
Why isn't the compiler able to deduce S[] => I[]? Or is it just
me?
I've tried dmd 2.075
More information about the Digitalmars-d-learn
mailing list