类模板"class has no constructors"错误
"class has no constructors" error for class template
我正在制作一个链表,我只想在列表的前面添加一个节点。 我做错了什么?
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 ==========
阅读错误消息:
使用类模板需要模板参数列表
new Node(entry)
应该new Node<T>(entry)
相关文章:
- "error: no matching function for call to"构造函数错误
- 调用专用模板时出错"no matching function for call to [...]"
- c++20[[no.unique_address]]中的新功能是什么
- 以线程安全的方式调用"QQuickPaintedItem::updateImage(const QImage&image)"(no QThread)
- "no matching function for call to 'Vector::Vector'"错误
- Android NDK clang 编译器错误在 Windows 上显示'No such file or directory'
- 处理"no operator found"
- 我在 ifstream input_file(文件名)行中收到错误"no matching function to call";
- 如何解决"no Qt platform plugin could be initialized"问题?
- "Unable to start debugging. No process is associated with this object." - 在Visual Studio Code中使用GDB
- 为什么当我在 std::string 中打开文件名的 fstream 时出现"no matching function"错误?
- 已解决 - C++ 的崇高文本中的"fatal error: opencv: no such file or directory"
- do while 循环中的 if 语句以 yes 或 no 结尾
- 从 TVector2 类派生复杂类:"No matching function for call to Complex::Complex()"
- 错误消息:使用"string* +="后"no match for 'operator+='"
- Eulers 项目问题 no 345 听不懂几行代码
- "No-Const Pointer to Const "调用功能
- 如何在 c++ 中将 s1 和 s2 与 no if 语句进行比较
- "No such file or directory" C++标头问题
- 类模板"class has no constructors"错误