Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c++;模板-指针中应包含类型说明符_C++_Templates_Pointers - Fatal编程技术网

C++ c++;模板-指针中应包含类型说明符

C++ c++;模板-指针中应包含类型说明符,c++,templates,pointers,C++,Templates,Pointers,这是一个链表,我正在尝试实现一个函数(Push),将项目添加到列表的顶部。 出于某种原因,节点*nnode=新节点函数内部给了我一个错误:“节点”前面应该有类型说明符。。这就是我的教授教我如何实现堆栈、链表等 我是不是实施错了?我查看了其他网站,它们的链表代码几乎相同 #ifndef Linked_List_h #define Linked_List_h template <typename ItemType> class Node { public: It

这是一个链表,我正在尝试实现一个函数(Push),将项目添加到列表的顶部。 出于某种原因,节点*nnode=新节点函数内部给了我一个错误:“节点”前面应该有类型说明符。。这就是我的教授教我如何实现堆栈、链表等

我是不是实施错了?我查看了其他网站,它们的链表代码几乎相同

#ifndef Linked_List_h
#define Linked_List_h

template <typename ItemType>
class Node
{
    public:
        ItemType Data;
        Node <ItemType> *next;
};

template <typename ItemType>
class Linked_List
{
        public:
        Node <ItemType> *start;
        Linked_List();
        int Push(ItemType newitem);
}
#endif
\ifndef链接列表\u h
#定义链接列表
模板
类节点
{
公众:
项目类型数据;
节点*下一步;
};
模板
类链表
{
公众:
节点*启动;
链表();
int Push(ItemType newitem);
}
#恩迪夫

#包括“Linked_List.h”
模板
链接列表::链接列表(){
start=NULL;
}
模板
int Linked_List::Push(const ItemType newitem){
节点*nnode=new节点;//不工作
nnode->Data=newitem;
nnode->next=开始;
开始=n节点;
返回1;
}
这有帮助吗

Node < ItemType > *nnode = new Node< ItemType >;
                               ^
                               typo correction
节点*nnode=新节点;
^
打字错误更正
这有帮助吗

Node < ItemType > *nnode = new Node< ItemType >;
                               ^
                               typo correction
节点*nnode=新节点;
^
打字错误更正

我认为“node”应该是“node”…

我认为“node”应该是“node”…

对于这个愚蠢的问题,我感到非常抱歉。。希望我不会因为这件事而被禁止。感谢you@Foxic:一点也不。相反,您以正确的方式提出了问题,提供了(选定的)格式良好的代码以及错误消息。对于这个愚蠢的问题,我感到非常抱歉。。希望我不会因为这件事而被禁止。感谢you@Foxic:一点也不。相反,通过提供(选定的)格式良好的代码以及错误消息,您以正确的方式提出了问题。