I'm new to C++, and I have undertaken learning generics and advanced data structures.
I was able to create a parent class called Collection
that is extended by the LinkedList
class. In that, and in implementing most of the features I wanted, I succeeded.
However, the last feature that I would like to implement is a toLinkedList()
function from the parent class.
Collection.h
#include"LinkedList.h"
template <class E>
class Collection {
public:
...
LinkedList<E> toLinkedList();
};
LinkedList.h
#include "Collection.h"
template <class E>
class LinkedList : public Collection<E> {
public:
...
LinkedList<E> toLinkedList();
};
LinkedList.cpp
#include "LinkedList.h"
#include "Collection.h"
template <class E>
LinkedList<E> LinkedList<E>::toLinkedList() {
LinkedList<E> out = LinkedList<E>();
LinkedNode<E> current = head;
while (current != NULL) {
out.add(current);
current = current->next;
}
return *out;
}
The idea is that the LinkedList
and future data structures could all be converted into a LinkedList
object.
As far as I know, everything should be OK, however I am getting an error when I attempt to define the LinkedList<E> toLinkedList()
function:
no template named LinkedList<E>