Why isn't intended class constructor called?

Alex sascha.orlov at gmail.com
Mon Jan 28 19:33:05 UTC 2019


On Monday, 28 January 2019 at 19:24:21 UTC, Zak wrote:
> On Monday, 28 January 2019 at 19:15:04 UTC, Zak wrote:
>> On Monday, 28 January 2019 at 18:50:18 UTC, Alex wrote:
>>> On Monday, 28 January 2019 at 18:34:44 UTC, Zak wrote:
>>>> [...]
>>>
>>> As the error states:
>>> you are trying to append an int to a string array in the 
>>> single parameter constructor.
>>>
>>> [...]
>>
>> Thanks for the response, Alex!  But it's not clear to me why 
>> the first constructor is called at all.  Since I called with 
>> two parameters, shouldn't it invoke the second constructor?
>
> I think I just realized the answer:  this section of code is 
> not called, it just fails compilation since it's not known that 
> runtime doesn't do something like:
>
> auto myc = new MyClass!(int, string)([1,2,-3]);
>
> which "would" invoke this code block with type string.

Yes. :)


More information about the Digitalmars-d-learn mailing list