Templates 模板错误:未定义的引用

Templates 模板错误:未定义的引用,templates,linked-list,Templates,Linked List,我正在尝试使用模板创建类linkedList,但编译时IDE出现错误: 对`listType::add(int)的未定义引用 我不明白为什么 linkedList.h #ifndef LINKEDLISTS_H_INCLUDED #define LINKEDLISTS_H_INCLUDED #include "struct.h" template <class type1> class listType { public: void add(type1); void print(

我正在尝试使用模板创建类linkedList,但编译时IDE出现错误: 对`listType::add(int)的未定义引用 我不明白为什么

linkedList.h

#ifndef LINKEDLISTS_H_INCLUDED
#define LINKEDLISTS_H_INCLUDED
#include "struct.h"
template <class type1>

class listType
{
public:

void add(type1);
void print();
private:
node<type1> *head;
};


#endif // LINKEDLISTS_H_INCLUDED
#如果包含链接列表#
#定义包含的链接列表
#包括“struct.h”
模板
类列表类型
{
公众:
无效添加(类型1);
作废打印();
私人:
节点*头;
};
#endif//包含链接列表

LinkedList.cpp

#include "linkedLists.h"
#include "struct.h"
#include <iostream>
using namespace std;

template <class type1>
void listType<type1>::add(type1 temp)
{
node<type1> *t;
t->value=temp;
t->link=head;
head=t;
}
template <class type1>
void listType<type1>::print()
{
node<type1> *p;
p=head;
while(p!=NULL)
{

    cout<<p->value<<endl;
    p=p->link;
}

}
#包括“LinkedList.h”
#包括“struct.h”
#包括
使用名称空间std;
模板
无效列表类型::添加(类型1临时)
{
节点*t;
t->值=温度;
t->link=头部;
水头=t;
}
模板
void listType::print()
{
节点*p;
p=水头;
while(p!=NULL)
{

不能在cpp文件中实现模板化类和函数

代码必须在头文件中,以便包含的文件可以看到实现,并使用模板参数类型实例化正确的版本

#ifndef STRUCT_H_INCLUDED
#define STRUCT_H_INCLUDED
template <class type1>

struct node
{

type1 value;
node *link;
};


#endif // STRUCT_H_INCLUDED
#include <iostream>
#include "linkedLists.h"
using namespace std;


int main()
{
listType <int> test;
test.add(5);

}