Weird combo of static function, templates, interfaces (that doesn't link)

0xEAB desisma at heidel.beer
Sun Dec 30 13:05:33 UTC 2018


> void main()
> {
>     StaticThingy.register(new SomeAdapter());
>     StaticThingy.createSome!Dummy();
> }
>
>
> interface FooAdapter
> {
>     FooBundle!(Handle) createSome(Handle)();
> }
>
> private class SomeAdapter : FooAdapter
> {
>     Bundle createSome()
>     {
>         auto w = new Dummy();
>         auto c = new FooDummy();
>         auto b = Bundle(c, w);
>         return b;
>     }
> }
>
> struct StaticThingy
> {
> static:
>     FooBundle!(Handle) createSome(Handle)()
>     {
>         return fooAdapter.createSome!(Handle)();
>     }
>
> // ...


> error: undefined reference to 
> '_D9onlineapp10FooAdapter__T10createSomeTCQBn5DummyZQyMFZSQCd__T9FooBundleTQBiZQp'
> collect2: error: ld returned 1 exit status
> Error: linker exited with status 1


Hey :)

During playing around I came up with code similar to the example 
above.

As the title says, this code doesn't link.
For the full example please see: https://run.dlang.io/is/mr0u2i

- But should this even compile successfully?
- Does `SomeAdapter` even implement `FooAdapter` correctly?


  ~ Elias


More information about the Digitalmars-d-learn mailing list