Well, it happened to me once [1], and the reason is that templated functions are final by default (since, as you said, it doesn't make sense for them to be anything else).

This way the body of the function is assumed to be in a different compilation unit (which is not, hence the linker error). If the variable had been declared of type "Foo" instead of "Asd" it would probably had worked, although this kind of defeat the purpose.

Whether it makes sense that this construction is allowed, is a different question. I personally it makes sense to have the user explicitly ask for "final", since we have otherwise "virtual by default", so this behaviour is completely unexpected be most users. The whole thing makes even less sense if you take into account that a explicit request to override is just silently ignored.

Finally, have also in mind that if the function had been declared abstract (as it arguably should), a compile-time error would have been generated [2].

[1]: http://forum.dlang.org/post/kgxwfsvznwzlnhrdp...@forum.dlang.org
[2]: https://dpaste.dzfl.pl/22f7e0840f01




On 07/06/2017 08:48 AM, rikki cattermole wrote:
>
> Templates+classes = require function body.
>
> Why? Templated methods are not virtual, they are final and cannot be
> inherited (so its a little strange that the override is valid).

Reply via email to