Dlang Polymorphism doesn't work as expected.
Enjoys Math
enjoysmath at gmail.com
Sun Sep 4 17:36:24 UTC 2022
I have the following MWE:
```
import std.exception;
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();
a();
readln();
return 0;
}
```
But B.opCall() gets called! I thought polymorphism was cool
until now....
How can I get this to work the way I expected it to? Would an
abstract method in base do it?
More information about the Digitalmars-d
mailing list