编译时头文件出错,求大家知道如何改?(数据结构顺序表头文件,源文件没有关问题,)最怕头文件出错,蛋疼
编译时头文件出错,求大家知道怎么改?(数据结构顺序表头文件,源文件没问题,)最怕头文件出错,蛋疼!
错误提示:
--------------------Configuration: data structures - Win32 Debug--------------------
Compiling...
data1.cpp
c:\program files\microsoft visual studio\data structures\seqlist.h(45) : error C2059: syntax error : ''template<''
c:\program files\microsoft visual studio\data structures\seqlist.h(46) : error C2065: 'T' : undeclared identifier
c:\program files\microsoft visual studio\data structures\seqlist.h(56) : error C2904: 'T' : template-name already defined as 'int T'
c:\program files\microsoft visual studio\data structures\seqlist.h(58) : error C2143: syntax error : missing ';' before '{'
c:\program files\microsoft visual studio\data structures\seqlist.h(58) : error C2447: missing function header (old-style formal list?)
c:\program files\microsoft visual studio\data structures\seqlist.h(64) : error C2954: template definitions cannot nest
执行 cl.exe 时出错.
data1.obj - 1 error(s), 0 warning(s)
源代码:
#include"linearlist.h"
template <class T>
class SeqList:public LinearList<T>
{
public:
SeqList(int MaxListSize);
~SeqList() { delete [] elements; };
bool IsEmpty() const;
int Length() const;
bool Find(int k,T& x) const;
int Search(const T& x) const;
bool Insert(int k,const T& x);
bool Delete(int k);
bool Update(int k, const T&x);
void Output(ostream& out)const ;
private:
int length;
int MaxLength;
T *elements; //动态一维数组
};
template <class T>
SeqList<T>::SeqList(int MaxListSize)
{
MaxLength=MaxListSize;
elements=new T[MaxLength];
length=0;
}
template <class T>
bool SeqList<T>::IsEmpty() const
{
return length==0;
}
template <class T>
int SeqList<T>::Length() const
{
return length;
}
template <class T>
template <class T>
bool SeqList<T>::Find(int k,T &x) const
{
if (k<1 || k>length) {
cout<<"Out of Bounds"<<endl;
return false;
}
x=elements[k-1];
return true;
}
template<class T>
int SeqList<T>::Search(const T& x) const
{
for (int i=0;i<length;i++)
if (elements[i]==x) return ++i;
return 0;
}
template<class T>
bool SeqList<T>::Insert(int k,const T& x)
错误提示:
--------------------Configuration: data structures - Win32 Debug--------------------
Compiling...
data1.cpp
c:\program files\microsoft visual studio\data structures\seqlist.h(45) : error C2059: syntax error : ''template<''
c:\program files\microsoft visual studio\data structures\seqlist.h(46) : error C2065: 'T' : undeclared identifier
c:\program files\microsoft visual studio\data structures\seqlist.h(56) : error C2904: 'T' : template-name already defined as 'int T'
c:\program files\microsoft visual studio\data structures\seqlist.h(58) : error C2143: syntax error : missing ';' before '{'
c:\program files\microsoft visual studio\data structures\seqlist.h(58) : error C2447: missing function header (old-style formal list?)
c:\program files\microsoft visual studio\data structures\seqlist.h(64) : error C2954: template definitions cannot nest
执行 cl.exe 时出错.
data1.obj - 1 error(s), 0 warning(s)
源代码:
#include"linearlist.h"
template <class T>
class SeqList:public LinearList<T>
{
public:
SeqList(int MaxListSize);
~SeqList() { delete [] elements; };
bool IsEmpty() const;
int Length() const;
bool Find(int k,T& x) const;
int Search(const T& x) const;
bool Insert(int k,const T& x);
bool Delete(int k);
bool Update(int k, const T&x);
void Output(ostream& out)const ;
private:
int length;
int MaxLength;
T *elements; //动态一维数组
};
template <class T>
SeqList<T>::SeqList(int MaxListSize)
{
MaxLength=MaxListSize;
elements=new T[MaxLength];
length=0;
}
template <class T>
bool SeqList<T>::IsEmpty() const
{
return length==0;
}
template <class T>
int SeqList<T>::Length() const
{
return length;
}
template <class T>
template <class T>
bool SeqList<T>::Find(int k,T &x) const
{
if (k<1 || k>length) {
cout<<"Out of Bounds"<<endl;
return false;
}
x=elements[k-1];
return true;
}
template<class T>
int SeqList<T>::Search(const T& x) const
{
for (int i=0;i<length;i++)
if (elements[i]==x) return ++i;
return 0;
}
template<class T>
bool SeqList<T>::Insert(int k,const T& x)