template member function confusion

Jonathan M Davis jmdavisProg at gmx.com
Sun Apr 8 15:07:47 PDT 2012


On Sunday, April 08, 2012 23:59:01 Francois Chabot wrote:
> I was already  aware of the non-virtualness of templates, and to
> tell the truth, I much prefer it this way. Maybe it's my C++
> background showing here, but is this something people have been
> asking for? It sounds crazy to me.

Of course, it's something that people have been asking for. It would be 
fantastic to be able to have templated functions which are virtual. And if you 
don't really understand how templates work or don't think it through enough, 
it seems crazy that they _wouldn't_ be virtual. But there are very practical 
reasons why doing so is more or less infeasible (it's certainly infeasible 
with how things currently work in D), and once it's explained how templates 
don't interact with virtual tables very well and all that, it becomes pretty 
obvious that there's no way that templates can be virtual.

There's no question that there are people who want it though. And the fact 
that some stuff in D really needs to be templated (e.g. a lot of range-based 
stuff really only works well if it's templated, and you can't support multiple 
string types very well without templates) makes it so that the lack of virtual 
templates in classes can be frustrating at times.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list