c++ - error: expected template-name before ’<’ token

浏览:37日期:2023-05-18

问题描述

我采用的Linux系统gcc编译器,编译程序的时候出现'error: expected template-name before ’<’ token',自己搞不懂是哪里出了问题,非常感谢。代码粘贴的有点多,望见谅。

相关代码

// 文件test.c++#include <iostream> #include 'List/LList.h'using namespace std; #include <stdlib.h>int main ( int argc, char *argv[] ) {LList<int> list;for (int i = 1; i <= 10; i ++){ list.append(i);} cout << 'size of first: ' << alist.length() << endl; return EXIT_SUCCESS; }// 文件LList.h#include<assert.h> #include<iostream> #define defaultSize 100 using namespace std;// Singly linked list node template <typename E> class Link { public:E element;Link *next; Link(const E& elemval, Link *nextval = NULL) { element = elemval; next = nextval;}Link(Link* nextval = NULL) { next = nextval;} };// Linked List implementation template <typename E> class LList: public List<E> { private:Link<E>* head;Link<E>* tail;Link<E>* curr;int cnt;void init() { curr = tail = head = new Link<E>; cnt = 0;}void removeall() { while(head != NULL) {curr = head;head = head->next;delete curr; }}public:// ConstructorLList(int size = defaultSize) { init(); }// Destructor~LList() { removeall(); } // Print list contentsvoid print() const; // Clear list;void clear() { removeall();init(); } // Insert 'it' at current positionvoid insert(const E& it) { curr->next = new Link<E>(it, curr->next); if(tail == curr) tail = curr->next; cnt ++;} // Append 'it' to listvoid append(const E& it) { tail = tail->next = new Link<E>(it, NULL); cnt ++;} // Remove and return current elementE remove() { Assert(curr->next != NULL && 'No element'); // Remember value E it = curr->next->element; // Remember link node Link<E> *ltemp = curr->next; // Reset tail if(tail == curr->next) tail = curr; // Remove from list curr->next = curr->next->next; // Reclaim space delete ltemp; cnt --; return it;} // Put curr at start of listvoid moveToStart() { curr = head;} // Put curr at end of listvoid moveToEnd() { curr = tail;} // Put curr one step at left, no change if already at frontvoid prev() { if(curr == head) return; Link<E>* temp = head; while(temp->next != curr) temp = temp->next; curr = temp;} // Move curr one step at right, nochange if already at lastvoid next() { if(curr != tail) curr = curr->next;} // Return lengthint length() const { return cnt; } // Return position of current elementint currPos() const { Link<E>* temp = head; int i; for(i = 0; curr != temp; i ++) {temp = temp->next; } return i;} // Move current to 'pos'void moveToPos(int pos) { Assert((pos >= 0) && (pos <= cnt) && 'Position out of range'); curr = head; for(int i = 0; i < pos; i ++) curr = curr->next;} // Return current valueconst E& getValue() const { Assert(curr->next != NULL && 'No value'); return curr->next->element;} };

报错信息

// Linked List implementation template <typename E> class LList: public List<E> {

代码这里编译出现错误:error: expected template-name before ’<’ token

相关截图c++ - error: expected template-name before ’<’ token

自己已经百度相关template相关解答。

问题解答

回答1:

class LList: public List {这里的List没有定义吧

相关文章: