That's the problem I had mentioned, though - the type of the entire array being 
inferred from the first element rather than the context (i.e. what it's 
initializing if not declared as 'auto') or subsequent elements (which would be 
a bit difficult...).
When I try that, the compiler prints this error message: (formatted for this 
context)
"Error: cannot implicitly convert expression (new BadChild) of type BadChild to 
GoodChild"

I'm not sure what a good syntax replacement would be. C# / Java style new array 
instantiations wouldn't really fit in syntactically with the already 
established style of arrays. But maybe there's a way the type of an array coud 
be explicitly stated without having to cast to make the type inference correct.


Jérôme M. Berger Wrote:

>       I would replace the last line with:
> Base[] list = [ new GoodChild, new BadChild, ...];
> 
>       It's clearer, there's less typing and it won't suddenly fail if you
> remove the first element and accidentally remove the cast at the
> same time or if you add a new first element and forget to add the
> cast...
> 
>               Jerome

Reply via email to