I have an inner class in myIterator
my template class linearLinkedList<T>
, and I would like to override the inherited virtual methods from simpleIterator<T>
, but the compiler rejects them, because "templates cannot be virtual." Based on this question , it seems that this should be possible, since it depends only on the type of the class. For example, the method foo
in my code below is legal. How can I implement virtual functions of the inner class?
template <class T>
class linearLinkedList
{
public:
...
virtual void foo(T data);
simpleIterator<T> * iterator();
private:
...
class myIterator : public simpleIterator<T>
{
public:
myIterator(node<T> ** head);
virtual ~myIterator();
private:
node<T> ** prev;
node<T> ** next;
virtual bool hasNext_impl();
virtual T next_impl();
virtual void remove_impl();
};
...
template<class T>
virtual linearLinkedList<T>::myIterator::~myIterator() { ... }
->
linearLinkedList.h:213:1: error: templates may not be Γ’virtualΓ’
virtual linearLinkedList<T>::myIterator::~myIterator()
source
share