LNK2019: 无法解析的外部符号
//---------------list.h
#pragma once
#include "stdafx.h"
#include <iostream>
using namespace std;
template <class T>
class LinearList
{
public:
LinearList(int len=10);
~LinearList();
bool IsEmpty() const;
int Length() const;
bool Find(int k,const T& x)const;
int Search(const T& x) const;
LinearList<T>& Delete(int k,T& x) ;
LinearList<T>& Insert(int k,const T& x);
void Output(ostream& out) const;
friend ostream& operator <<(ostream& out,const LinearList<T>& x);
private:
int length;
T*element;
int MaxSize;
};
//----------list.cpp
#include "stdafx.h"
#include"list.h"
template<class T> LinearList<T>::LinearList(int len)
{
MaxSize=len;
element=new T[len];
length=0;
}
template<class T> LinearList<T>::~LinearList()
{
delete[]element;
}
template<class T>
bool LinearList<T>::IsEmpty() const
{
return length==0;
}
template<class T>
int LinearList<T>::Length() const
{
return length;
}
template<class T>
bool LinearList<T>::Find(int k,const T &x) const
{
if(k<=0||k>length)
{
cout<<"none !"<<endl;
return false;
}
else
{
x=element[k-1];
return true;
}
}
template<class T>
int LinearList<T>::Search(const T &x) const
{
int i;
for(i=0;i<length&&x!=element[i];i++);
if(i==length)
return 0;
else
return ++i;
}
template<class T>
LinearList<T>& LinearList<T>::Delete(int k, T &x)
{
if(Find(k,x))
{
for(int i=k;i<length;i++)
element[i-1]=element[i];
length--;
return *this;
}
else
cout<<"error !"<<endl;
}
template<class T>
LinearList<T>& LinearList<T>::Insert(int k, const T &x)
{
if(k<1||k>length)
cout<<"error !"<<endl;
if(length==MaxSize)
cout<<"full !"<<endl;
for(int i=length-1;i>=k-1;i--)
element[i+1]=element[i];
element[k-1]=x;
length++;
return*this;
}
template<class T>
void LinearList<T>::Output(ostream &out) const
{
for(int i=0;i<length;i++)
out<<element[i]<<" ";
}
template<class T>
ostream& operator <<(ostream& out,const LinearList<T>& x)
{
x.Output(out);
return out;
}
//-------------------------- Win32_DS3_1.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "list.h"
int _tmain(int argc, _TCHAR* argv[])
{
LinearList<int>L(5);
cout << "Length = " << L.Length() << endl;
cout << "IsEmpty = " << L.IsEmpty() <<endl;
L.Insert( 0 , 2 ).Insert ( 1 , 6 ) ;
cout << "List is " << L <<endl;
cout << "IsEmpty = " << L.IsEmpty() << endl;
int z;
L .Find ( 1 , z ) ;
cout << "First element is " << z << endl;
cout << "Length = " << L.Length() << endl;
L .Delete( 1 , z ) ;
cout << "Deleted element is " << z << endl;
cout << "List is " << L << endl;
return 0;
}
程序调试 老是出这个问题 找不着原因 求高手解答~~~~
1>Win32_DS3_1.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall LinearList<int>::~LinearList<int>(void)" (??1?$LinearList@H@@QAE@XZ),该符号在函数 _wmain 中被引用
1>Win32_DS3_1.obj : error LNK2019: 无法解析的外部符号 "public: class LinearList<int> & __thiscall LinearList<int>::Delete(int,int &)" (?Delete@?$LinearList@H@@QAEAAV1@HAAH@Z),该符号在函数 _wmain 中被引用
1>Win32_DS3_1.obj : error LNK2019: 无法解析的外部符号 "public: bool __thiscall LinearList<int>::Find(int,int const &)const " (?Find@?$LinearList@H@@QBE_NHABH@Z),该符号在函数 _wmain 中被引用
1>Win32_DS3_1.obj : error LNK2019: 无法解析的外部符号 "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class LinearList<int> const &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABV?$LinearList@H@@@Z),该符号在函数 _wmain 中被引用
1>Win32_DS3_1.obj : error LNK2019: 无法解析的外部符号 "public: class LinearList<int> & __thiscall LinearList<int>::Insert(int,int const &)" (?Insert@?$LinearList@H@@QAEAAV1@HABH@Z),该符号在函数 _wmain 中被引用
1>Win32_DS3_1.obj : error LNK2019: 无法解析的外部符号 "public: bool __thiscall LinearList<int>::IsEmpty(void)const " (?IsEmpty@?$LinearList@H@@QBE_NXZ),该符号在函数 _wmain 中被引用
1>Win32_DS3_1.obj : error LNK2019: 无法解析的外部符号 "public: int __thiscall LinearList<int>::Length(void)const " (?Length@?$LinearList@H@@QBEHXZ),该符号在函数 _wmain 中被引用
1>Win32_DS3_1.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall LinearList<int>::LinearList<int>(int)" (??0?$LinearList@H@@QAE@H@Z),该符号在函数 _wmain 中被引用