Initialize array of objects not work

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 4 13:18:42 PDT 2016


On 08/04/2016 09:06 AM, Steven Schveighoffer wrote:
> On 8/4/16 11:19 AM, Andre Pany wrote:
>> On Thursday, 4 August 2016 at 13:48:46 UTC, Steven Schveighoffer wrote:
>>> On 8/3/16 2:34 PM, Ali Çehreli wrote:
>>>
>>>> void main() {
>>>>     Element[] elements = cast(Element[])[ quadraticCoefficient(1),
>>>> linearCoefficient(2), equals(), constant(1) ];
>>>
>>> is the cast necessary? I assumed the compiler would infer the common
>>> base type...
>>>
>>> -Steve
>>
>> I just tested it. The compiler cannot infer interface Element.
>> By changing the type from interface to class the compiler
>> is happy without the cast.
>> Does it worth to open an enhancement request for this specific issue?
>
> Ah, it's an interface. I thought it was a base class.
>
> This is expected, no need to open a request.
>
> -Steve
>

Oh! I see now: Since there is a linear hierarchy line among classes, 
it's possible to determine the closest common ancestor. That's not 
possible for interfaces due to multiple interface inheritance.

Ali



More information about the Digitalmars-d-learn mailing list