#ifndef Seqlist_H
#define Seqlist_H
const size_t maxsize = 10 ;
template
class seqlist
{
private:
datatype data [ maxsize ] ;
int length ;
public:
seqlist(){ length = 0 ; } ;
seqlist( datatype a[] , int size ) ;
~seqlist(){} ;
int set_length (){ return length ; } ;
datatype get( int i ) ;
int locate( datatype x ) ;
void insert ( int i , datatype x ) ;
datatype delete_element( int i ) ;
void printlist() ;
};
#endif
#include "SeqList.h"
template
seqlist :: seqlist ( datatype a[] ,int n )
{
if ( n > maxsize )
throw "参数非法" ;
for ( size_t i = 0 ; i < n ; i ++ )
{
data[i] = a[i] ;
}
length = n ;
}
template
datatype seqlist :: get ( int i )
{
if ( i < 1 || i > length )
throw "查找的位置非法" ;
else
return data[i-1] ;
}
template
int seqlist ::locate( datatype x )
{
for ( size_t i = 0 ; i < length ; i ++ )
{
if ( data[i] == x )
return i-1 ;
}
return 0 ;
}
template
void seqlist::insert( int i , datatype x )
{
if ( length > maxsize )
throw "上溢" ;
if ( i < 1 || i > length )
throw "插入的位置非法" ;
for ( size_t j = length ; j > i ; j-- )
{
data[j] = data[j-1] ;
}
data[i-1] = x ;
length ++ ;
}
template
datatype seqlist :: delete_element( int i )
{
if ( length == 0 )
throw "下溢" ;
if ( i < o || i > length )
throw "位置非法" ;
x = data[i-1] ;
for ( size_t j = i ; j < length ; j++ )
data[j-1] = data[j] ;
length -- ;
return x ;
}
template
void seqlist :: printlist()
{
for ( size_t i = 0 ; i < length ; i ++ )
std::cout << data[i] << " " ;
}
#include
#include "SeqList.h"
void main()
{
int Array_text [maxsize] ;
std::cout << "请输入 10 个数字 :" << std::endl ;
for ( size_t i = 0 ; i < maxsize ; i ++ )
std::cin >> Array_text [maxsize] ;
seqlist <int> text1( Array_text , maxsize ) ;
text1.printlist() ; // 代码现在此处加了断点调试,不晓得为什么会出现以下错误
}
错误提示:
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall seqlist::seqlist(int * const,int)" (??0?$seqlist@H@@QAE@QAHH@Z),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: void __thiscall seqlist::printlist(void)" (?printlist@?$seqlist@H@@QAEXXZ),该符号在函数 _main 中被引用
1>F:\C++初始\seqlist_use\Debug\seqlist_use.exe : fatal error LNK1120: 2 个无法解析的外部命令
怎么回事,求大神告知!!!
感激不尽!!!