【发布时间】:2012-10-17 04:25:15
【问题描述】:
我收到此消息,其中包含 Node* 的所有内容(此声明没有存储或类型说明符)。有人可以帮忙,请给我正确的方向吗?
template <typename type>
Node* Stack<type>::pop() {
Node* retNode; // the node to be return
if(tos == NULL) {
cerr << "*** Stack empty ***";
exit(1);
}
else {
retNode = tos; // store the location of tos
tos = tos->getLink(); // move to new tos
retNode->setLink(); // unlink the popped node from the stack
size -= 1;
}
return retNode;
}
我确定它正在处理Node*,但我就是不知道是什么。
以下是我对堆栈类中使用的节点类的声明。如果您还需要我对堆栈类的声明,请告诉我,因为我看不到问题所在。
template <typename type>
class Node<type>{
private:
type data;
Node *link;
public:
Node(type p_item, Node *p_link);
type getData() const;
Node* getLink() const;
void setData(type p_data);
void setLink(Node *node);
};
【问题讨论】:
-
在编译此代码之前,您必须在范围内声明
Node。那么,它在哪里? -
对不起,我一直在努力理解这个网站在评论部分放置代码的方法,但我仍然遇到问题。
-
不要在 cmets 中发布该代码,只需编辑您的原始帖子。
-
非常感谢。我没有意识到这一点,并认为人们希望我们对此发表评论。
-
很明显,
Node是一个模板,所以您需要使用Node<type> *而不是Node *(假设要使用的type与您使用的Stack相同)模板)。
标签: c++ templates compiler-errors