I have an inner class, myIterator
, of my template class linearLinkedList<T>
, and I'd like to override inherited virtual methods from simpleIterator<T>
, but the compiler is rejecting them as "templates may not be virtual." Based on this question, though, it seems like this should be possible, as it only depends on the class's type. For example method foo
in my code below is legal. How can I implement the virtual functions of the inner class?
template <class T>
class linearLinkedList
{
public:
...
virtual void foo(T data); //OK
simpleIterator<T> * iterator();
private:
...
class myIterator : public simpleIterator<T>
{
public:
myIterator(node<T> ** head);
virtual ~myIterator(); //inherited from simpleIterator; error when implemented
private:
node<T> ** prev;
node<T> ** next;
//functions inherited from simpleIterator<T>:
virtual bool hasNext_impl(); //error when implemented
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()