Possible Duplicate:
Can a member function template be virtual?
In a base class, the function my_func
is defined as virtual. However, in the derived class I would like to have my_func
to be a template method. Is this possible?
It seems it isn't. I get the error "cannot allocate an object of abstract type", which I believe it is related to the fact that the compiler does not acknowledge the override of the virtual my_func
in the base class. Does this reveal a poor design maybe?
Thanks a lot.
UPDATE: Thanks for the answers. Some of you are suggesting I should post some of the code, so here it is. In the base class:
virtual void Fill(EventInfo* info, EasyChain* tree, vector<Muon*>& muons, vector<Electron*>& electrons, vector<Jet*>& jets, LorentzM& met) = 0;
But in the derived class I would like to have:
template<typename _Jet>
void Fill(EventInfo* info, EasyChain* tree, vector<Muon*>& muons_in, vector<Electron*>& electrons_in, vector<_Jet>& jets_in, LorentzM& met){
From your answers, I understand that a solution to the problem would be to define another function in the derived class:
void Fill(EventInfo* info, EasyChain* tree, vector<Muon*>& muons, vector<Electron*>& electrons, vector<Jet*>& jets, LorentzM& met){
//
}
but then, this function and the template function are the same for the case of _Jet
being Jet*
, wouldn't that be a problem as well?
Some have suggested a design problem here, I guess that's true, I'll have to think about how to go around this then.
template
method cannot bevirtual
, so it can never override anyvirtual
method. – Glottalizedoverride
keyword, present in C++11 if I say well. There’re only advantages to do so, no drawback ;) – Saida