预期的类型说明符错误,关于我做错了什么的任何想法?
expected type-specifier error, any ideas as to what I am doing wrong?
我正在尝试使用双链表实现 DEQUE。
DEQUE.h
using namespace std;
template <typename T>
class Node{
Node(const T& data):data(data), next(0), prev(0) {}
public:
Node* next;
Node* prev;
T data;
};
template <typename T>
class DEQUE
{
//interface
};
DEQUE.cpp
template <class T>
void DEQUE< T > ::AddFirst(T t){
Node<T>* temp = new Node(t);
if ( counter != 0 ) {
temp->next = head;
temp->prev = 0 ;
head->prev = temp;
head =temp;
counter++;
}
else{
head = temp;
tail = temp;
temp->next = 0;
temp->prev = 0;
counter++;
}
};
我在行'Node'错误之前得到预期的类型说明符
Node<T>* temp = new Node(t);
我在这里做错了什么?提前感谢您的帮助。
您在创建 Node
的实例时忘记了类型:
Node<T>* temp = new Node<T>(t);
^^^ missing.
用于创建 Node
实例的类型不会自动假定为与用于 DEQUE
的类型相同。您必须明确指定它。
我正在尝试使用双链表实现 DEQUE。
DEQUE.h
using namespace std;
template <typename T>
class Node{
Node(const T& data):data(data), next(0), prev(0) {}
public:
Node* next;
Node* prev;
T data;
};
template <typename T>
class DEQUE
{
//interface
};
DEQUE.cpp
template <class T>
void DEQUE< T > ::AddFirst(T t){
Node<T>* temp = new Node(t);
if ( counter != 0 ) {
temp->next = head;
temp->prev = 0 ;
head->prev = temp;
head =temp;
counter++;
}
else{
head = temp;
tail = temp;
temp->next = 0;
temp->prev = 0;
counter++;
}
};
我在行'Node'错误之前得到预期的类型说明符
Node<T>* temp = new Node(t);
我在这里做错了什么?提前感谢您的帮助。
您在创建 Node
的实例时忘记了类型:
Node<T>* temp = new Node<T>(t);
^^^ missing.
用于创建 Node
实例的类型不会自动假定为与用于 DEQUE
的类型相同。您必须明确指定它。