数据结构再c++中的运用,麻烦大家给与指点,错在哪里!不胜感激!!

在文件“linearlist.h”中#ifndef_LINEARLIST_H#define_LINEARLIST_H#include<iostream.h>//线性表的抽... 在文件“linearlist.h”中
#ifndef _LINEARLIST_H
#define _LINEARLIST_H
#include <iostream.h>//线性表的抽象类
template<class T>
class linearlist
{
public:
linearlist ();
virtual ~linearlist()=0;
virtual bool isenpty () const {return length==0;}
virtual int Length () const {return length;}
virtual bool find(int k, T &x) const=0;
virtual bool Delete (int k, T &x)=0;

virtual bool insert ( int k,const T &x)=0;
virtual void output (ostream &out ) const=0;
/* virtual int locate (T &x)=0;*/
/* virtual void purgel() const=0; //老师,这个函数定义是正确的吗????*/
protected:
long length;
};

class nomem//异常类的定义
{
public:
nomem() {cout <<"memory is not enough";};
};
class outofbounds
{
public:
outofbounds(){cout<<"out of bounts "<<endl;}
};
#endif
在文件“linearlistsqu.h”
#ifndef _LINEARLISTSQU_H
#define _LINEARLISTSQU_H
#include "linearlist.h"//线性表的抽象类
template<class T>
class linearlistsqu:public linearlist<T>//定义函数
{
public:
linearlistsqu (int Maxlistsize=10);
virtual ~linearlistsqu(){if (element) delete[]element;}
virtual bool isenpty () const {return length==0;}
virtual int Length () const {return length;}
virtual bool find(int k, T &x) const=0;
virtual bool Delete (int k, T &x)=0;

virtual bool insert ( int k,const T&x)=0;
virtual void output (ostream &out ) const=0;
/* virtual int locate (T &x)=0;*/
/* virtual void purgel() const=0;*/
protected:
long length;
long Maxsize;
T *element;
};

template<class T>
linearlistsqu<T>::linearlistsqu(int Maxlistsize)
{
Maxsize=Maxlistsize;
try{ element=new T[Maxsize];}
catch(...) {throw nomem();}
length=0;
}

template<class T>
bool linearlistsqu<T>::find(int k, T &x) const
{
if (k<1||k>length) return false;
x=element[k-1];
return true;
}

template <class T>
void linearlistsqu<T>::output (ostream& out ) const
{
for (int i=0;i<length; i++) out<<element[i]<<" ";
}

template <class T>
ostream& operator<<(ostream& out,const linearlistsqu<T> & x)
{
x.output(out);
return out ;
}

template<class T>
bool linearlistsqu<T>::insert(int k,const T& x)
{
if (k<1||k>length) throw outofbounds ();
if (length==Maxsize) throw nomem();
for (int i=length-1; i>=k;i--) element[i-1]=element[i];
element[k]=x; length++;
return true;
}

template<class T>
bool linearlistsqu<T>::Delete(int k,T& x)
{
if (find(k,x))
{
for (int i=k;i<length; i++) element[i-1]=element[i];length--;
return true;
}
else throw outofbounds();
}
#endif
在“main。cpp"中是:
#include <iostream.h>
#include "linearlistsqu.h"
#include "linearlist.h"
void main ()
{
try {
linearlistsqu<int> L (5);
cout <<"length"<<L.Length()<<endl;
cout<<"isenpty="<<L.isenpty()<<endl;
bool ok=false;
int n,t;//n表示想在线性表中输入的数据的个数
cin>>n;
if (n<=10) //想输入的数据个数与线性表的长度做比较
for (int i=0;i<n;i++)
{
cout<<" Input data "<<i<<"="<<endl;
cin >>t;
ok=L.insert(i,t);
}

cout <<"list is"<<L<<endl;//输出线性表
cout<<"the length of the table is :"<<L.Length();//输出线性表的长度

int k,z;//查找位于第k个位置的元素z
cin>>k;
if(k==n||k<n)
{ L.find(k,z);
cout<<"The elements in the "<<k<<"is:"<<z<<endl;
L.Delete(k,z);
cout<<"delete the" <<k<<"element is "<<z<<endl;
}
else cout<<"This location does not exist in the table "<<endl;
}
catch(...) {cerr<<"An exception has occurred"<<endl;}
}

运行结果出现: error C2259: 'linearlistsqu<int>' : cannot instantiate abstract class due to following members:这是什么意思??怎么修改程序?

麻烦大家给点建议,本人真的不明白错在哪里,为什么总是运行不到呢??
如果这里回答的空间有限,也可以发到liruifeng171@126.com邮箱中告知我答案,我必然会加分给你,麻烦了。。。
展开
 我来答
冰火梦幻
2010-03-27 · TA获得超过2308个赞
知道小有建树答主
回答量:1095
采纳率:57%
帮助的人:414万
展开全部
这说明你的linearlistsqu是抽象类,里面那些纯虚函数是做什么的?不是已经实现了吗
把linearlistsqu里的
virtual bool find(int k, T &x) const=0;
virtual bool Delete (int k, T &x)=0;

virtual bool insert ( int k,const T&x)=0;
virtual void output (ostream &out ) const=0;
后面的=0去掉吧……

代码拷贝就是这一点可能疏忽
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式