Variadic Struct Parameter
Steven Schveighoffer
schveiguy at gmail.com
Tue Jan 12 20:49:56 UTC 2021
On 1/12/21 12:46 PM, Q. Schroll wrote:
> On Tuesday, 12 January 2021 at 17:26:15 UTC, Jonathan Levi wrote:
>> Why is this not working?
>>
>> ```
>> struct S {
>> int x;
>> string y;
>> }
>>
>> void fun(S s ...) {
>
> This is intended for arrays and classes, not structs. Using ... for
> something other than arrays and c
>
>> fun(S(5,"hi"));
>
> That one should compile...
>
>> fun(5,"hi");
>
> and the second one not.
>
> It's obvious why arrays work, it's the primary use case. I have no idea
> why classes are allowed. That classes are allowed, but structs are not,
> makes no sense to me.
Originally, structs did not allow a constructor. I'm thinking probably
when they got constructors, the (almost never-used) variadic form of
class parameter passing did not get ported to structs.
-Steve
More information about the Digitalmars-d-learn
mailing list