1

Possible Duplicate:
Template member function virtual?

Why are templated virtual member functions not allowed?
I was just playing around a bit with some sample code and the following code snippet gives me the error

"member function templates cannot be virtual"

#include<iostream.h>
#include<stdio.h>
class Base
{
    public: 
    template <class T> virtual void doSomething(T genVar,int val){}

};

class derivedCl:public Base
{
    public:
    template <class T> virtual void doSomething(T genVar, char ch){}
};

Is this a rule which the standard dictates and if so why?

Edit: I did a search before asking the Q but the dup never showed up. Now that Sbi pointed it out, I would vote for closing this one. Thanks!

Community
  • 1
  • 1
Alok Save
  • 202,538
  • 53
  • 430
  • 533

0 Answers0