template member function confusion

Francois Chabot francois.chabot.dev at gmail.com
Sun Apr 8 14:59:01 PDT 2012


> Two issues here.
>
> 1. You cannot currently overload a templated function with a 
> non-templated
> function or vice versa: 
> http://d.puremagic.com/issues/show_bug.cgi?id=1528
> This is a bug which should work and should work at some point.

Thank you very much for the confirmation that I'm not crazy here.

> The workaround
> is to templatize the non-templated functions with empty parens. 
> e.g.
>
> void foo()(Foo target, const ref Matrix44 val)

I could see this working, but I'll steer clear of this in this 
particular case. "Dirtying" the preferred interface just for the 
sake of a convenience function is not exactly... nice...

> 2. Template functions are non-virtual and will _never_ be 
> virtual. This probably isn't causing you any compilation 
> issues, but it does mean that you must be careful with using 
> templated functions in classes. It means that templatizing all 
> of the foos will mean that none of them are virtual (though 
> that's arguably better than making some of them virtual and 
> some not, since that has its own set of issues). Regardless, if 
> you have an API which relies on having a templated function be 
> virtual, you're going to have to find a way to work around it, 
> because templated functions _can't_ be virtual.

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.

Once again, thanks for the help!


More information about the Digitalmars-d-learn mailing list