Templates convariance

Boris Wang nano.kago at hotmail.com
Tue Jun 20 18:45:32 PDT 2006


"Sean Fritz" <Sean_member at pathlink.com> дÈëÏûÏ¢ÐÂÎÅ:e79r79$f64$1 at digitaldaemon.com...
> In article <e799ce$2idm$1 at digitaldaemon.com>, michal.minich at gmail.com 
> says...
>
> A list!(Shape) is not the same a a list!(Square).  It sounds like you want 
> some
> sort of wildcard matching or something to enforce type bounding like 
> Java/C#
> have, but casts are definitely unsafe.
>

agreed.

'cast' and 'static if' should not be a solution for this problem, if
we want a good programming language.


> Example code (I'm going to blotch various syntax, sorry in advance):
>
> void foo(List!(Shape) ls) {
> ls.add(new Circle) //passes type check locally?
> }
>
> ..
> List!(Square) ls = new List!(Square);
> foo(ls);
> //but ls now contains a Circle?  Circles don't go in List!(Square)?
> ,,.
>
>
> 





More information about the Digitalmars-d mailing list