szy5692976 2019-08-22 09:38 采纳率: 100%
浏览 365
已采纳

小白写c++模板类继承报错,实在不知道问题出在哪里求大神帮帮忙。

父类

template<typename EleType>
class Sequence {
public:
    Sequence();
    Sequence(int volumn);
    ~Sequence();
    int GetSize();
    bool IsEmpty();
    bool IsFull();
    bool DoubleVol();
    EleType& operator[](int index);
protected:
    int size;
    int volume;
    EleType* DataPointer;
    int begin;
    int end;
};

子类

template<typename EleType>
class Stack :public Sequence<EleType> {
public:
    Stack():Sequence<EleType>() {}
    Stack(int volume) :Sequence<EleType>(volume) {}
    ~Stack() {}
    bool Pop(EleType& data) {
        if (this->IsEmpty()) {
            return false;
        }
        --size;
        data = this->DataPointer[--end];
        return true;
    }
    bool Push(const EleType& data) {
        if (this->IsFull()) {
            if (!this->DoubleVol())
                return false;
        }
        this->DataPointer[end++] = data;
        ++size;
        return true;
    }
    bool GetTop(EleType& data) {
        if (size >= 1)
            return false;
        data = this->DataPointer[end];
        return true;
    }
};

报的错误是这个,我实例化父类没有什么问题。但是这个子类编译不通过,33行所在位置就是上面子类最后一行,也就是"};"所在行,百度了也没有找到合适的答案,求大神解答。
图片说明

  • 写回答

2条回答 默认 最新

  • qtchen_1988 2019-08-22 10:01
    关注

    父类不变

    子类如下:

    template<typename EleType>
    class Stack :public Sequence<EleType> {
    public:
        Stack():Sequence<EleType>() {}
        Stack(int volume) :Sequence<EleType>(volume) {}
        ~Stack() {}
        bool Pop(EleType& data) {
            if (this->IsEmpty()) {
                return false;
            }
            --this->size;
            data = this->DataPointer[--this->end];
            return true;
        }
        bool Push(const EleType& data) {
            if (this->IsFull()) {
                if (!this->DoubleVol())
                    return false;
            }
            this->DataPointer[this->end++] = data;
            ++this->size;
            return true;
        }
        bool GetTop(EleType& data) {
            if (this->size >= 1)
                return false;
            data = this->DataPointer[this->end];
            return true;
        }
    };
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集