Implicit Constructors
Jacob Carlborg
doob at me.com
Fri Oct 13 06:33:14 UTC 2017
On 2017-10-13 01:57, Q. Schroll wrote:
> We have some sort of implicit construction already. Weirdly, it's
> reserved for classes. Just look at this:
>
> class C { this(int x) { } }
> void foo(C c ...) { }
> void main() { foo(0); }
Hmm, I didn't know that syntax was legal. But apparently it's some form
of typesafe variadic function [1]. It also work for built-in types:
void foo(int i ...){}
void main()
{
foo(3);
foo(3, 4); // error, too many arguments
}
Not sure what the purpose of the latter is.
[1] https://dlang.org/spec/function.html#typesafe_variadic_functions
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list