On Sunday, 18 June 2023 at 19:05:19 UTC, rempas wrote:
On Sunday, 18 June 2023 at 18:17:16 UTC, Paul Backus wrote:

`__ctor` doesn't create a new object, it initializes an existing object. You need to create the object first, then call `__ctor` on it:

```d
void main() {
  Test test;
  test.__ctor!("non_def")("Hello");
}
```

Thank you! Do you know any other way to do it without using "__ctor".

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");
}
```

Reply via email to