need `this` for `this` of type `ref @safe Test(string reg_arg)

rempas rempas at tutanota.com
Sun Jun 18 20:50:52 UTC 2023


On Sunday, 18 June 2023 at 19:22:45 UTC, Paul Backus wrote:
>
> No, there is no way to pass template arguments to a constructor 
> without using `__ctor`.
>
> My recommendation is to use a free function or a `static` 
> method instead. For example:
>
> ```d
> import std.stdio;
>
> struct Test {}
>
> Test makeTest(string type = "def")(string reg_arg)
> {
>     writeln("reg_arg: ", reg_arg);
>     return Test();
> }
>
> void main()
> {
>     auto test = makeTest!"non_def"("Hello");
> }
> ```

Thank you! This will make me change the design of my API a little 
bit but it will do ;)


More information about the Digitalmars-d-learn mailing list