【求助】数据结构题= =
浏览量:8138 回帖数:3
1楼
显示错误 undefined reference to `operator+(seqList<int> const&, seqList<int> const&)
程序在这里:+法,=,复制构造都编了,但是还是有错= =
template <class elemType> class seqList;
template <class T> seqList<T> operator+(const seqList<T> &a,const seqList<T> &b);
template <class elemType>
class seqList:public List<elemType>
{
friend seqList<elemType> operator+(const seqList<elemType> &a,const seqList<elemType> &b);
………………
seqList(const seqList &a);
………………
seqList &operator=(const seqList &a);
………………
};
template <class T>
seqList<T> operator+(const seqList<T> &a,const seqList<T> &b)
{
int alen=a.Length(),blen=b.Length();
seqList<T> c(alen+blen);
for (int i=0;i<alen;i++)
c.data[i]=a.data[i];
for (int i=0;i<blen;i++)
c.data[i+alen]=b.data[i];
c.currentLength=alen+blen;
return c;
}
template <class elemType>
seqList<elemType>::seqList(const seqList<elemType> &a)
{
data=new elemType[a.maxSize];
if (!data) throw IllegalSize();
for (int i=0;i<a.currentLength;i++)
data[i]=a.data[i];
maxSize=a.maxSize;
currentLength=a.currentLength;
template <class elemType>
seqList<elemType> &seqList<elemType>::operator=(const seqList<elemType> &a)
{
if (this==&a) return *this;
delete [] data;
data=new elemType[a.maxSize];
if (!data) throw IllegalSize();
for (int i=0;i<a.currentLength;i++)
data[i]=a.data[i];
maxSize=a.maxSize;
currentLength=a.currentLength;
return *this;
}
显示错误 undefined reference to `operator+(seqList<int> const&, seqList<int> const&)
程序在这里:+法,=,复制构造都编了,但是还是有错= =
template <class elemType> class seqList;
template <class T> seqList<T> operator+(const seqList<T> &a,const seqList<T> &b);
template <class elemType>
class seqList:public List<elemType>
{
friend seqList<elemType> operator+(const seqList<elemType> &a,const seqList<elemType> &b);
………………
seqList(const seqList &a);
………………
seqList &operator=(const seqList &a);
………………
};
template <class T>
seqList<T> operator+(const seqList<T> &a,const seqList<T> &b)
{
int alen=a.Length(),blen=b.Length();
seqList<T> c(alen+blen);
for (int i=0;i<alen;i++)
c.data[i]=a.data[i];
for (int i=0;i<blen;i++)
c.data[i+alen]=b.data[i];
c.currentLength=alen+blen;
return c;
}
template <class elemType>
seqList<elemType>::seqList(const seqList<elemType> &a)
{
data=new elemType[a.maxSize];
if (!data) throw IllegalSize();
for (int i=0;i<a.currentLength;i++)
data[i]=a.data[i];
maxSize=a.maxSize;
currentLength=a.currentLength;
template <class elemType>
seqList<elemType> &seqList<elemType>::operator=(const seqList<elemType> &a)
{
if (this==&a) return *this;
delete [] data;
data=new elemType[a.maxSize];
if (!data) throw IllegalSize();
for (int i=0;i<a.currentLength;i++)
data[i]=a.data[i];
maxSize=a.maxSize;
currentLength=a.currentLength;
return *this;
}
发表于 2014/8/29 21:11:27

