Can't seem to call super constructor if it's a template

Alexandru Ermicioi alexandru.ermicioi at gmail.com
Wed Aug 12 11:32:19 UTC 2020


On Wednesday, 12 August 2020 at 11:10:42 UTC, Steven 
Schveighoffer wrote:
> On 8/12/20 2:22 AM, Alexandru Ermicioi wrote:
>> On Monday, 10 August 2020 at 18:37:06 UTC, Andrei Alexandrescu 
>> wrote:
>>> class A {
>>>     this(T)() {}
>>> }
>>>
>>> class B : A {
>>>     this() { super!int(); }
>>> }
>>>
>>> Error: found ! when expecting ; following statement
>>>
>>> That should work, shouldn't it?
>> 
>> It is not possible to call cobstructors with explicit template 
>> parameters. There was documentation note about that from what 
>> I remember, though for some reason I can't find yet.
>> 
>> Reason for that may be the case where you have templated class 
>> with templated constructor. How would user pass template args 
>> to class itself and then to constructor?
>
> A derived class doesn't have to pass template parameters to the 
> base type. super!T should be unambiguous.

Indeed it should, but that would be another edge case that would 
be usable just in derived classes and not in any other location, 
won't it?

Imho, it would make more confusing for new joiner, where he would 
expect same functionality to be available also for new 
expressions or during allocation using std.experimental.

I think we should not allow just this use case, but rather think 
on how can we chain multilple sets of template args, which would 
solve the thing also for new expressions too.

- Alex


More information about the Digitalmars-d mailing list