模板线性列表错误,链接错误 [英] Template linear list error, link errors
本文介绍了模板线性列表错误,链接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了三个文件来完成线性列表:
在main.cpp中:
I created three files to complete the linear list:
In main.cpp:
#include "stdafx.h"
#include "Seque.h"
int main(int argc, char* argv[])
{
printf("Hello World!\n");
int n,number,position1,insert1,position2;
Seque<int> seque;
cout<<"Input the number of numbers you want to enter!"<<endl;
cin>>n;
seque.Input(n);
seque.Output();
cout<<"Input the number you want to search!"<<endl;
cin>>number;
seque.SearchItem(number);
cout<<"Input the position and number you want to insert!"<<endl;
cin>>position1;
cin>>insert1;
seque.InsertItem(position1,insert1);
seque.Output();
cout<<"Input the position you want to delete!"<<endl;
cin>>position2;
seque.DeleteItem(position2);
seque.Output();
return 0;
}
在Seque.cpp中:
In Seque.cpp:
<pre lang="xml">#include "stdafx.h"
#include "Seque.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
template<class T>
Seque<T>::Seque(int sz)
{
listsize=sz;
lenth=-1;
elem= new T[listsize];
if (elem==NULL)
{
cerr<<"error"<<endl;
exit(1);
}
}
template<class T>
void Seque<T>::SearchItem(T& x)
{
for (int i=0;i<listsize;i++)
{
if (elem[i]==x)
{
cout<<"The number you search is at "<<i<<"th location"<<endl;
}
else
cout<<"Not Found!"<<endl;
}
}
template<class T>
void Seque<T>::InsertItem(int i, T& x)
{
if (lenth==listsize-1)
{
cout<<"full"<<endl;
}
for (int j=lenth;j>i;j--)
{
elem[j+1]=elem[j];
}
elem[i]=x;
lenth++;
}
template<class T>
void Seque<T>::DeleteItem(int i)
{
int x;
if (i>lenth)
{
cout<<"Exceed!"<<endl;
}
x=elem[i];
for (int j=i;j<=lenth;j++)
{
elem[j]=elem[j+1];
}
lenth--;
cout<<"The number at where you point is "<<x<<endl;
}
template<class T>
void Seque<T>::Input(int i)
{
if (i>listsize)
{
cout<<"Error!"<<endl;
break;
}
lenth=i;
cout<<"Input the elements!"<<endl;
for (int j=0;j<i;j++)
{
cout<<"Number"<<j+1<<endl;
cin>>elem[j];
}
}
template<class T>
void Seque<T>::Output()
{
for (int i=0;i<lenth;i++)
{
cout<<"Number "<<i+1<<":"<<endl;
cout<<elem[i]<<endl;
}
}
在Seque.h中:
In Seque.h:
<pre lang="xml">#if !defined(AFX_SEQUE_H__78600571_2F0D_49E2_B387_EA39796A31A6__INCLUDED_)
#define AFX_SEQUE_H__78600571_2F0D_49E2_B387_EA39796A31A6__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <iostream.h>
#include <stdlib.h>
#define Defaultsize 100
template <class T>
class Seque
{
private:
T *elem;
int lenth;
int listsize;
protected:
public:
Seque(int sz=Defaultsize);
~Seque(){delete[] elem;}
void InsertItem(int i, T& x);
void DeleteItem(int i);
void SearchItem(T& x);
void Input(int i);
void Output();
};
#endif // !defined(AFX_SEQUE_H__78600571_2F0D_49E2_B387_EA39796A31A6__INCLUDED_)
错误是:
Errors are:
Linking...
3 Main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Seque<int>::DeleteItem(int)" (?DeleteItem@?$Seque@H@@QAEXH@Z)
3 Main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Seque<int>::InsertItem(int,int &)" (?InsertItem@?$Seque@H@@QAEXHAAH@Z)
3 Main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Seque<int>::SearchItem(int &)" (?SearchItem@?$Seque@H@@QAEXAAH@Z)
3 Main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Seque<int>::Output(void)" (?Output@?$Seque@H@@QAEXXZ)
3 Main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Seque<int>::Input(int)" (?Input@?$Seque@H@@QAEXH@Z)
3 Main.obj : error LNK2001: unresolved external symbol "public: __thiscall Seque<int>::Seque<int>(int)" (??0?$Seque@H@@QAE@H@Z)
Debug/3 Main.exe : fatal error LNK1120: 6 unresolved externals
Error executing link.exe.
推荐答案
Seque @ H @@ QAEXH @ Z) 3 Main.obj:错误 LNK2001:无法解析的外部符号" public:void __thiscall Seque< int> ::: InsertItem(int,int&)"(?InsertItem @?
Seque@H@@QAEXH@Z) 3 Main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Seque<int>::InsertItem(int,int &)" (?InsertItem@?
Seque @ H @@ QAEXHAAH @ Z) 3 Main.obj:错误 LNK2001:无法解析的外部符号" public:void __thiscall Seque< int> :: SearchItem(int&)"(?SearchItem @?
Seque@H@@QAEXHAAH@Z) 3 Main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Seque<int>::SearchItem(int &)" (?SearchItem@?
Seque @ H @@ QAEXAAH @ Z) 3 Main.obj:错误 LNK2001:无法解析的外部符号" public:void __thiscall Seque< int> :: Output(void)"(?Output @?
Seque@H@@QAEXAAH@Z) 3 Main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Seque<int>::Output(void)" (?Output@?
这篇关于模板线性列表错误,链接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文