On Tuesday, 13 September 2022 at 00:57:58 UTC, Kyle Ingraham wrote:
I am writing a library where I would like to be able to store instances of a type of class to an associative array for later usage. Each class stored has to implement a function as part of the required interface. The argument given is always the same type but the return value should be flexible. I solved this with an interface:

```d
interface PathConverter
{
    T toD(T)(const string value) @safe;
}
```

https://dlang.org/spec/template.html#limitations

Templates cannot be used to add non-static fields or virtual functions to classes or interfaces.

You *should* get an error from the compiler for trying to do this, instead of just a linker error somewhere else down the line, but either way it's not going to work. You'll have to find another solution.

Reply via email to