c – 类模板的“类没有构造函数”错误
发布时间:2020-12-16 09:42:11 所属栏目:百科 来源:网络整理
导读:我正在创建一个链表,我只想在列表的前面添加一个节点.我究竟做错了什么? Node.h #pragma once namespace list_1 {template typename Tstruct Node{ T data; NodeT *next; // Constructor // Postcondition: NodeT (T d);};template typename TNodeT::Node(T
我正在创建一个链表,我只想在列表的前面添加一个节点.我究竟做错了什么?
Node.h #pragma once namespace list_1 { template <typename T> struct Node { T data; Node<T> *next; // Constructor // Postcondition: Node<T> (T d); }; template <typename T> Node<T>::Node(T d) { data = d; next = NULL; } } list.h template <typename T> void list<T>::insert_front(const T& entry) { Node<T> *temp = head; if(temp == NULL) temp->next = new Node(entry); else { while (temp->next != NULL) { temp = temp->next; } temp->next = new Node(entry); } } 错误信息; 1>------ Build started: Project: Linked List,Configuration: Debug Win32 ------ 1> list_test.cpp 1>c:...linked listlist.h(54): error C2955: 'list_1::Node' : use of class template requires template argument list 1> c:...linked listnode.h(7) : see declaration of 'list_1::Node' 1> c:...linked listlist.h(48) : while compiling class template member function 'void list_1::list<T>::insert_front(const T &)' 1> with 1> [ 1> T=double 1> ] 1> c:...linked listlist_test.cpp(33) : see reference to class template instantiation 'list_1::list<T>' being compiled 1> with 1> [ 1> T=double 1> ] 1>c:...linked listlist.h(54): error C2514: 'list_1::Node' : class has no constructors 1> c:...linked listnode.h(7) : see declaration of 'list_1::Node' 1>c:...linked listlist.h(62): error C2514: 'list_1::Node' : class has no constructors 1> c:...linked listnode.h(7) : see declaration of 'list_1::Node' ========== Build: 0 succeeded,1 failed,0 up-to-date,0 skipped ========== 解决方法
阅读错误消息:
新节点(条目)应该是新节点< T>(条目) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 宇宙最强调试器DDD(Data Display Debugger)
- SQLite数据升级数据迁移
- vue-auto-focus: 控制自动聚焦行为的 vue 指令方法
- 【唐巧】基于sqlite的key-value存储工具:YTKKeyValueStore
- Knockoutjs实战开发:属性监控(Observables)和依赖跟踪(
- ruby-on-rails – 缺少param或值为空
- 选择什么作为.NET应用程序的轻度infile nosql数据存储?
- 当参数传递给我的ruby脚本时,为什么会发生错误?
- 使用TProfiler分析并调优项目中的Fastjson序列化代码
- objective-c – 当调试器设置为LLDB时,Xcode 4在附加到(App