level 1
喜欢V喜欢
楼主
#ifndef SEQLIST_H#
define SEQLIST_H
#include using namespace std;
template class SeqList
{public:
SeqList(int InitSize); //构造函数
~SeqList( ); //析构函数
void Clear( ); //清空顺序表
bool IsEmpty( ) const {return (length == 0);} //表是否为空
bool IsFull( ){return (length == MasSize)} //表是否已满
int Length( ) const; //表的长度
ElemType Get(int i) const; //返回第i个结点的值
int Next(int i)const; //若第i个结点的直接后继结点存在,则返回其下标,否则返回0int Prior(int i)const; //若第i个的直接前驱结点存在,返回其下标,否则返回0
int Find(ElemType e); //返回值等于e的结点的序号,无则返回0
int Insert(int i,const ElemType& e); //在第i个位置上插入新的结点(值为e),并使原来的第i个结点至 //最后一个结点的序号依次加1。插入成功返回1,否则返回0
int Delete(ElemType& e,int i); //若第i个结点存在,删除并将其值放入e,若i非法,则删除失败,返回0
private:
ElemType* elem; //顺序表存储数组,存放实际的数据结点int length; //顺序表中结点的个数,即表的长度int MaxSize; //顺序表的最大可能长度(注意第一个结点用作哨兵)};
//异常处理函数
void Exception(int Condition,const char* ErrorMsg)
{
if (Condition)
{
cerr << ErrorMsg << endl;abort();
}
}
template SeqList::SeqList(int InitSize)
{
if (InitSize > 0)
{
elem = new ElemType[InitSize];
Exception(!elem,"there is no space in memory");length = 0;MaxSize = InitSize - 1;}}
……
然后VS报错说
1>testSeqList.obj : error LNK2005: "void __cdecl Exception(int,char const *)" (?Exception@@YAXHPBD@Z) 已经在 SeqList.obj 中定义
1>F:\program-work\try\Debug\try.exe : fatal error LNK1169: 找到一个或多个多重定义的符号
为什么啊!!!
2011年09月15日 14点09分
1
define SEQLIST_H
#include using namespace std;
template class SeqList
{public:
SeqList(int InitSize); //构造函数
~SeqList( ); //析构函数
void Clear( ); //清空顺序表
bool IsEmpty( ) const {return (length == 0);} //表是否为空
bool IsFull( ){return (length == MasSize)} //表是否已满
int Length( ) const; //表的长度
ElemType Get(int i) const; //返回第i个结点的值
int Next(int i)const; //若第i个结点的直接后继结点存在,则返回其下标,否则返回0int Prior(int i)const; //若第i个的直接前驱结点存在,返回其下标,否则返回0
int Find(ElemType e); //返回值等于e的结点的序号,无则返回0
int Insert(int i,const ElemType& e); //在第i个位置上插入新的结点(值为e),并使原来的第i个结点至 //最后一个结点的序号依次加1。插入成功返回1,否则返回0
int Delete(ElemType& e,int i); //若第i个结点存在,删除并将其值放入e,若i非法,则删除失败,返回0
private:
ElemType* elem; //顺序表存储数组,存放实际的数据结点int length; //顺序表中结点的个数,即表的长度int MaxSize; //顺序表的最大可能长度(注意第一个结点用作哨兵)};
//异常处理函数
void Exception(int Condition,const char* ErrorMsg)
{
if (Condition)
{
cerr << ErrorMsg << endl;abort();
}
}
template SeqList::SeqList(int InitSize)
{
if (InitSize > 0)
{
elem = new ElemType[InitSize];
Exception(!elem,"there is no space in memory");length = 0;MaxSize = InitSize - 1;}}
……
然后VS报错说
1>testSeqList.obj : error LNK2005: "void __cdecl Exception(int,char const *)" (?Exception@@YAXHPBD@Z) 已经在 SeqList.obj 中定义
1>F:\program-work\try\Debug\try.exe : fatal error LNK1169: 找到一个或多个多重定义的符号
为什么啊!!!