contravariant argument types: wanna?

Steven Schveighoffer schveiguy at yahoo.com
Tue Sep 22 18:28:14 PDT 2009


On Tue, 22 Sep 2009 21:21:10 -0400, Jeremie Pelletier <jeremiep at gmail.com>  
wrote:
>
> Also about contravariance, using your original A and B objects, what  
> would happen in the following case:
>
> void main() {
> 	A a = new B;
> 	a.fun(new A); // Error! (in theory)
> }
>
> Should the compiler disallow the call or assume there can be a  
> contravariant overload? what happens if theres another subclass  
> requiring a B argument in the a.fun(new A); call.

This will not compile, An A does not implicitly cast to a B.

-Steve



More information about the Digitalmars-d mailing list