C++ 没有参数列表的模板名称的无效使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18186878/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
invalid use of template name without an argument list
提问by Alladin
I am facing a problem with my linked list class, I have created the interface and implementation files of the class, but when I build it, this error occurs: "invalid use of template name 'LinkedList' without an argument list". here's my interface file:
我的链表类遇到了问题,我已经创建了该类的接口和实现文件,但是当我构建它时,会出现此错误:“模板名称‘LinkedList’的无效使用没有参数列表”。这是我的接口文件:
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
template <typename T>
struct Node{
T info;
Node<T> *next;
};
template <typename T>
class LinkedList
{
Node<T> *start;
Node<T> *current;
public:
LinkedList();
~LinkedList();
};
#endif // LINKEDLIST_H
and this is my implementation code:
这是我的实现代码:
#include "LinkedList.h"
LinkedList::LinkedList()
{
start = nullptr;
current = nullptr;
}
LinkedList::~LinkedList()
{
}
回答by jrok
Write it like this:
像这样写:
template<typename T>
LinkedList<T>::LinkedList()
{
start = nullptr;
current = nullptr;
}
And similarly for other member functions. But you'll run into another problem - declarations and definitions of a template can't be separatedto different files.
其他成员函数也类似。但是您会遇到另一个问题 - 模板的声明和定义不能分离到不同的文件。