I tried to use a typedef type as a return type for my member function, I don't know why it is giving me this "LinkedList" is not a class error. Can someone please give me a hint?
template<class T>
class LinkedList {
struct Node;
public:
typedef Node* lstIterator;
lstIterator insert_after(const_lstIterator position, const T& );
// other code
private:
struct Node {
T data;
Node *next;
// default constructor
Node() = default;
// constructor with data
Node(const T& data) : data(data), next(NULL) {}
};
lstIterator head;
};
template<typename T>
LinkedList::lstIterator LinkedList<T>::insert_after(const_lstIterator position, const T& val) {
^^^^^^^^^^^^^^^^^^^^^
error: "LinkdedList" is not a class, namespace or scoped enumeration
}
Use
instead, as
LinkedList
is a template class. You needtypename
sinceLinkedList<T>::lstIterator
is a dependent name.