Having some issues using Generator's yield with an interface
Ben via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Nov 2 21:52:26 PST 2015
When I create a generator using an interface (or abstract class)
I must cast the concrete instance to the interface. Why does the
Generator not know that B is a implementation of the interface of
A?
/// Test Code
interface A {}
class B : A{}
// Fails
auto testGen1 = new Generator!A({
yield (new B());
});
// Succeeds
auto testGen2 = new Generator!A({
yield ( cast(A) new B());
});
More information about the Digitalmars-d-learn
mailing list