virtual methods and template classes
Posted
by soxs060389
on Stack Overflow
See other posts from Stack Overflow
or by soxs060389
Published on 2010-03-27T21:45:20Z
Indexed on
2010/03/27
21:53 UTC
Read the original article
Hit count: 249
Hi
I got over a problem, I think a very specific one.
I've got 2 classes, a B aseclass and a D erived class (from B aseclass).
B is a template class ( or class template) and has a pure virtual method virutal void work(const T &dummy) = 0;
The D erived class is supposed to reimplement this, but as D is Derived from B rather than D being another template class, the compiler spits at me that virtual functions and templates don't work at once.
Any ideas how to acomplish what I want?
I am thankfull for any thoughts and Ideas, especially if you allready worked out that problem
this class is fixed aka AS IS, I can not edit this without breaking existing code base
template <typename T>
class B {
public:
...
virtual void work(const T &dummy) = 0;
..
};
take int* as an example
class D : public B<int*>{
...
virtual void work(const int* &dummy){ /* put work code here */ }
..
};
Edit: The compiler tells me, that void B<T>::work(const T&)
[with T = int*]
is pure virtual within D
© Stack Overflow or respective owner