Hi All,
I am trying to implement generic link list in c++ .
But getting below error .
Please assist me to correct it.
LinkedList.hpp
LinkNode<E>* head; errr: unknown tpe name ''LinkNode
// LinkNode.hpp
// cplus
//
// Created by Ravi Rathore on 10/12/15.
#ifndef LinkNode_hpp
#define LinkNode_hpp
#include <stdio.h>
#include "LinkedList.hpp"
template <typename E>
class LinkNode {
private:
E elem;
LinkNode<E>* next;
//friend class LinkedList<T>;
};
#endif /* LinkNode_hpp */
// LinkedList.hpp
// cplus
//
// Created by Ravi Rathore on 10/12/15.
// Copyright © 2015 Banago labs. All rights reserved.
//
#ifndef LinkedList_hpp
#define LinkedList_hpp
#include <stdio.h>
#include "LinkNode.hpp"
template <typename E>
class LinkedList
{
private:
LinkNode<E>* head;
public:
LinkedList();
~LinkedList();
bool empty() const;
const E& front() const;
void addFront(const E& e);
void removeFront();
};
#endif /* LinkedList_hpp */
//
// LinkedList.cpp
// cplus
//
// Created by Ravi Rathore on 10/12/15.
// Copyright © 2015 Banago labs. All rights reserved.
//
#include "LinkedList.hpp"
template <typename E>
LinkedList<E>::LinkedList()
{
head=NULL;
}
template <typename E>
LinkedList<E>::~LinkedList(){
while (!empty()) {
removeFront();
}
}
template <typename E>
bool LinkedList<E>::empty() const{
return head==NULL;
}
template <typename E>
const E& LinkedList<E>::front() const{
return head->elem;
}
template <typename E>
void LinkedList<E>::addFront(const E& e)
{
LinkNode<E>* node = new LinkNode<E>;
node->elem = e ;
node->next = head;
head = node;
}
template <typename E>
void LinkedList<E>::removeFront()
{ LinkNode<E>* old = head;
head = old ->next;
delete old;
}
Regards,
Ravi