Virtual templates possible?

Started by
1 comment, last by Mantear 17 years, 6 months ago
Greetings, I've got a base class with many classes that derive from it. I want the base class to have a templated function. Most of the derived classes will use the base class template version, but a couple derived classes need their own implemention. Is this possible? The compiler (VS 2005 Express) says that I cannot use 'virtual' with 'template'. I simply tried to over-ride the template function in the dervied class (identical function signature, etc), but the base class version was still called. How can I do this? Will I have to resort to overloading instead of templates? Thanks!
Advertisement
It's not possible to have virtual templates (but C++/CLI can have virtual generics but thats another story), the way to emulate them involve class templates and alot of repetitive boilerplate code (which to a certain extent can be reduced with the help of boost metaprogramming facilities).
So am I just best off making some function in the base class, void Base::Foo(), and overload it with all the types I'll need? ie, Foo(unsigned int), Foo(bool), Food(std::string), etc. And then in the derived class that won't use the base class implemention, just over-ride all of the overloaded functions?

This topic is closed to new replies.

Advertisement