On Wednesday, 12 March 2014 at 13:12:20 UTC, Steven Schveighoffer
wrote:
On Wed, 12 Mar 2014 09:05:05 -0400, Steve Teale
<[email protected]> wrote:
How is the compiler to build it's one copy of bad? Should x be
typed as A or B? Or something not even seen in this module that
could derive from I?
-Steve
Let's take bad() away, and instead:
class A : I
{
A myType() { return cast(A)null;}
final void foo();
}
class B : I
{
B myType() {return cast(B) null;}
final void bar();
}
void main()
{
I[] arr = [new A, new B];
foreach(i; arr) { (cast(typeof(i.myType()) i).foo() }
}
myType() is a virtual function, so calling it through the
interface type should get the correct version right?, and then
the cast should cause a call to A or B.