C++描述线性表调试错误(希望大家指点下)
#include<iostream>using namespace std;
template<typename T>
class sqlist
{
private:
int mm,length;
T *v;
public:
sqlist(){mm=0;length=0;return;}
sqlist(int);
void printsqlist();
//int flagsqlist();//
void insqlist(int ,T);
void deisqlist(int);
//void sortsqlist();//
};
template<class T>
void sqlist<T>::printsqlist()
{
int i;
cout<<"length="<<length<<endl;
for(i=0;i<length;i++)cout<<v[i]<<" ";
cout<<endl;
}
template<class T>
int sqlist<T>::insqlist(int i,T a)
{
int k;
if(mm==length){cout<<"溢出"<<endl;return;}
if(i>n)i=n+1;
if(i<1)i=1;
for(k=length;k>i;k--)
v[k]=v[k-1];
v[i-1]=a;
length++;
return;
}
template<class T>
void sqlist<T>::deisqlist(int i)
{
int k;
if(length==0)
{cout<<"非法,表空"<<endl;return;}
if(i<1||i>length)
{cout<<"位置错误"<<endl;return;}
for(k=i;k<length;k++)
v[k-1]=v[k];
length--;
return;
}
//template<class T>
//void sqlist::sortsqlist()
//{
//}//
void main()
{
int k,a[10]={1,2,3,4,5,6,7,8,9,10};
sqlist<int> s(20);
for(k=1;k<=10;k++)
s.insqlist(k,a[k-1]);
s.printsqlist();
}
调试错误:
:\program files\microsoft visual studio\myprojects\1\1.cpp(38) : error C2244: 'sqlist<T>::insqlist' : unable to resolve function overload
c:\program files\microsoft visual studio\myprojects\1\1.cpp(39) : error C2954: template definitions cannot nest
Error executing cl.exe.