Dlang Polymorphism doesn't work as expected.

rikki cattermole rikki at cattermole.co.nz
Sun Sep 4 17:46:02 UTC 2022


This appears to be working correctly.

You override the implementation of opCall in A, so when you called 
opCall, it called the implementation of it in A. B's opCall never landed 
in the vtable.

It does in fact return an A object.

```d
import std.stdio;

abstract class B
{
    B opCall() {
       throw new Exception("NotImplemented");
    }
}

class A : B
{
    override B opCall() {
       return new A();
    }
}

int main() {
    B a = new A();

    auto got = a();
    assert(got !is null);
    writeln(got);

    return 0;
}
```


More information about the Digitalmars-d mailing list