Jump to content
  • Advertisement
Sign in to follow this  
Mantear

Virtual templates possible?

This topic is 4324 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!