digitalmars.D.learn - Weird combo of static function, templates, interfaces (that doesn't
- 0xEAB (8/39) Dec 30 2018 Hey :)
- =?UTF-8?Q?Ali_=c3=87ehreli?= (9/18) Dec 30 2018 Function templates cannot be virtual functions. One reason is the
- 0xEAB (3/22) Jan 02 2019 Thanks for the technical explanation.
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 1Hey :) 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
Dec 30 2018
On 12/30/2018 05:05 AM, 0xEAB wrote:Function templates cannot be virtual functions. One reason is the compiler cannot know how large the virtual function table should be, and the other one is it's just a template, not the real thing (i.e. not a function).interface FooAdapter { FooBundle!(Handle) createSome(Handle)(); }SomeAdapter.createSome is a function unrelated to FooAdapter.createSome. Their only relationship is through "name hiding."private class SomeAdapter : FooAdapter { Bundle createSome()- Does `SomeAdapter` even implement `FooAdapter` correctly?Yes because FooAdapter has no virtual function. :p~ EliasAli
Dec 30 2018
On Sunday, 30 December 2018 at 18:55:10 UTC, Ali Çehreli wrote:On 12/30/2018 05:05 AM, 0xEAB wrote:Thanks for the technical explanation. ~ EliasFunction templates cannot be virtual functions. One reason is the compiler cannot know how large the virtual function table should be, and the other one is it's just a template, not the real thing (i.e. not a function).interface FooAdapter { FooBundle!(Handle) createSome(Handle)(); }SomeAdapter.createSome is a function unrelated to FooAdapter.createSome. Their only relationship is through "name hiding."private class SomeAdapter : FooAdapter { Bundle createSome()- Does `SomeAdapter` even implement `FooAdapter` correctly?Yes because FooAdapter has no virtual function. :p~ EliasAli
Jan 02 2019