I'm building a C++ list program. There is an ADT List which is a purely virtual template class, which SLL (singly linked list) inherits from. I've written the class definition in sll.h and attempted to implement the list in sll.cpp. However I keep getting the following two errors,
1)
In file included from cpp_files/sll.cpp:1:0,
from main.cpp:3:
cpp_files/../includes/sll.h:3:25: error: expected class-name before ‘{’ token
class SLL : public List {
2)
cpp_files/../includes/sll.h:12:54: error: cannot declare member function ‘List<L>::insert’ within ‘SLL’
void List<L>::insert( L element, int position );
My question, what is going on? Why does this not work?
SLL.cpp
#include "../includes/sll.h"
/*
Singly Linked List Implementation
*/
SLL::SLL() {}
SLL::~SLL() {}
template <class L>
void List<L>::insert( L element, int position ) {
}
SLL.H
#include "../includes/list.h"
class SLL : public List {
private:
public:
SLL();
~SLL();
template <class L>
void List<L>::insert( L element, int position );
};
List.h
#ifndef LIST_H
#define LIST_H
/*
In this code we define the headers for our ADT List.
*/
template<class L>
class List {
private:
public: // This is where functions go
typedef struct node {
int data;
node* next;
} * node_ptr;
virtual void insert( L element, int position ) = 0;
};
#endif // LIST_H