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:
interface PathConverter
{
T toD(T)(const string value) @safe;
}
That interface lets me type the associative array and any other part of the library that needs to use implementers of that interface e.g.
PathConverter[string] converters;
The problem I'm running into is that when compile the library I receive the following error during linking:
error LNK2019: unresolved external symbol _D3app13PathConverter__T3toDTAyaZQjMFNfxAyaZQp referenced in function _D3app14TypedURLRouter__T10setHandlerTPFNfC4vibe4http6server17HTTPServerRequestCQBlQBjQBh18HTTPServerResponseAyaZvZQDmMFEQDaQCy6common10HTTPMethodQBlQEhZ__T9__lambda4TQEvTQDoTASQGt16PathCaptureGroupZQBrMFNfQGiQFaQBlZv
fatal error LNK1120: 1 unresolved externals
Error: linker exited with status 1120
The call is within a delegate to a function that returns a class instance from the associative array. At runtime I fill the associative array. The call looks like this:
tailArgs[i] = getPathConverter("id string").toD!(Parameters!(handler)[i])("string to convert");
Am I running into this error because the linker can't find the instantiation of the template method? How would I give the linker the information it needs? Is there a better way to have an interface with flexible return values?