class A {
virtual This a() { return this }
}
class B : A {
override This a() { return super.a }
}
I get
Cannot return ::A as ::B this
B return type should be substituted instead of This in super.a, shouldn't it?
brianFri 19 Nov 2010
This returns is one place where auto-casting isn't used by the compiler, rather it really checks that the result type is exactly the type of the containing class. So in that case you need to manually instead a cast to B in the B.a method.
tonsky Fri 19 Nov 2010
When trying to compile following
I get
B
return type should be substituted instead ofThis
insuper.a
, shouldn't it?brian Fri 19 Nov 2010
This
returns is one place where auto-casting isn't used by the compiler, rather it really checks that the result type is exactly the type of the containing class. So in that case you need to manually instead a cast toB
in theB.a
method.