//Lnode.h文件
#pragma once
template<class T>
class Lnode
{
public:
T data;
Lnode<T>* next;
Lnode(int,Lnode<T>*);
~Lnode(void);
};
//Lnode.cpp文件
#include "Lnode.h"
template<class T>
Lnode<T>::Lnode(int el,Lnode<T>* ne):data(el),next(ne)
{
}
template<class T>
Lnode<T>::~Lnode(void)
{
}
//linkedlist.h文件
#pragma once
#include"Lnode.h"
template<class T>
class linkedlist
{
public:
linkedlist(void);
~linkedlist(void);
void pushfront(int);
void print();
private:
Lnode<T> *head;
unsigned int t;
};
//linkedlist.cpp文件
#include "linkedlist.h"
#include<iostream>
using namespace std;
template<class T>
linkedlist<T>::linkedlist(void)
{
head=0;
t=0;
}
template<class T>
linkedlist<T>::~linkedlist(void)
{
Lnode<T> * buf;
while(t!=0)
{
buf=head;
head=head->next;
delete buf;
t--;
}
}
template<class T>
void linkedlist<T>::pushfront(int el)
{
head=new Lnode<T>(a,head);
t++;
}
template<class T>
void linkedlist<T>::print()
{
Lnode<T>* buf_head=head;
while(buf_head)
{
cout<<buf_head->data;
buf_head=buf_head->next;
}
}
//主函数文件
#include"linkedlist.h"
void main()
{
linkedlist<int> list;
list.pushfront(9);
list.pushfront(6);
list.pushfront(5);
list.print();
}
//错误信息:
1>template.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall linkedlist<int>::~linkedlist<int>(void)" (??1?$linkedlist@H@@QAE@XZ),该符号在函数 _main 中被引用
1>template.obj : error LNK2019: 无法解析的外部符号 "public: void __thiscall linkedlist<int>::print(void)" (?print@?$linkedlist@H@@QAEXXZ),该符号在函数 _main 中被引用
1>template.obj : error LNK2019: 无法解析的外部符号 "public: void __thiscall linkedlist<int>::pushfront(int)" (?pushfront@?$linkedlist@H@@QAEXH@Z),该符号在函数 _main 中被引用
1>template.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall linkedlist<int>::linkedlist<int>(void)" (??0?$linkedlist@H@@QAE@XZ),该符号在函数 _main 中被引用
1>c:\users\sunny\documents\visual studio 2010\Projects\template\Debug\template.exe : fatal error LNK1120: 4 个无法解析的外部命令