auto attribute for interface functions

Jonathan M Davis jmdavisProg at gmx.com
Tue Oct 8 12:05:17 PDT 2013


On Tuesday, October 08, 2013 17:26:04 Roman wrote:
> Seems, I've tried to use virtual templates manner. But it doesn't
> realizes in D yet

Fundamentally, making templates virtual doesn't really work. If it's possible, 
it would be quite difficult, and AFAIK, it's impossible. Templated functions 
aren't actual functions - they're templates for functions. The code isn't 
generated until the template is instantiated, which pretty much only happens 
when the function is called. And it's unknown when the template is written 
what types are going to be used with it. In fact, since the template could be 
in a library, and code could use that library well after the library has been 
written, it's quite possible for the types that will be used with the template 
to not even have been conceived yet when the template is written. Contrast 
this with virtual functions which must sit in the virtual table of a class. 
They have to be known when the class is compiled. As such, there is a 
fundamental conflict between how templates work and how virtual functions work. 
They just don't mix.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list