0
語境:我有一類Node
這樣的:「類不是一個模板」
#ifndef NODE_H_
#define NODE_H_
template <class T>
class Node
{
private:
T data;
Node* next;
Node* previous;
public:
Node();
Node(T);
~Node();
};
#endif /* NODE_H_ */
和A類ListDE
這樣的:
/*
* ListDE.h
*
* Created on: Apr 22, 2013
* Author: x
*/
#ifndef LIST_H_
#define LIST_H_
#include <iostream>
#include <fstream>
#include <string>
#include "Node.h"
using namespace std;
template <class T>
class ListDE
{
private:
int qElements;
Node<T>* start;
Node<T>* getNextNode(Node<T>* aNode);
public:
ListDE();
~ListDE();
Node<T> getFirstPosition();
int getQNodes();
void setQNnodes(int q);
Node<T>* getNode(int pos);
T get_data(int pos);
void change_value(int pos, T newValue);
void add_new_data(T data);
void concat(ListDE<T>* otherList);
void delete_last();
};
#endif /* LIST_H_ */
問題:當我試圖編譯,我得到這些錯誤:
ListDE.h:24:5: error: ‘Node’ is not a template
ListDE.h:26:5: error: ‘Node’ is not a template
ListDE.h:26:34: error: ‘Node’ is not a template
ListDE.h:32:5: error: ‘Node’ is not a template
ListDE.h:35:5: error: ‘Node’ is not a template
任何人都可以向我解釋這是什麼意思?謝謝!
它聽起來倒退,但將您的構造函數實現放入.cpp文件可能是問題。取決於你如何處理你的模板。一般來說,模板化函數defs放在標題中。 – ChiefTwoPencils 2013-05-07 04:16:20
我想你必須給每個'NODE'變量和'LISTDE'變量賦予'template parameters',因爲在LISTDE類 – thunderbird 2013-05-07 04:22:01
@thunderbird中定義了一個或多個節點變量,我不太明白你的意思:S – 2013-05-07 04:32:11