抽象类linearList

来源:互联网 发布:残兵屠龙熔炼数据 编辑:程序博客网 时间:2024/06/07 10:21
template<class T>class linearList{    public :    virtual ~linearList(){};    virtual bool empty() const =0;    virtual int size() const = 0;    virtual T& get(int theIndex) const =0;    virtual int indexOf(const T& theElement) const =0;    virtual void erase(int the Index) = 0;    virtual insert(int theIndex, const T& theElement) = 0;    virtual void output(ostream& out) const =0;}

要点:
1、一个抽象类的派生类,只有实现了基类的所有纯虚函数才是具体类,否则依然是抽象类而不能实例化。
2、把抽象类的析构函数定义为虚函数,目的是,当一个线性表的实例离开作用域时,需要调用的缺省析构函数是引用对象中数据类的析构函数。
3、关键字const指明这些函数不会改变调用对象的值(即调用对象的属性),我们把这种函数称为常量函数。