各位大佬们想用c++实现一下线性表,为啥会报错呢

#include<iostream>
using namespace std;
#define ERROR 0;
#define OVERFLOW -2;
#define OK 1;
#define MaxSize 100;
//线性表顺序存储结构c++实现
template<typename T>
class SqlList {
public:
    SqlList() {};
    SqlList(int Size) {
        m_size = Size;
        Elem = new T[Size];
        m_length = 0;
    }
    T& operator [](int x)
    {
        if (x >= m_length)
        {
            throw - 1;
        }
        else
        {
            return Elem[x];
        }
    }
    void Getm_length() {
        return m_length;
    }
    void Getm_size() {
        return m_size;
    }
    int InsertSqlList(int Position,T item) {
        if (Position<1 || Position>m_length+1) {
            return ERROR;
        }
        else if (m_length + 1 > m_size) {
            return OVERFLOW;
        }
        else {
            for (int i = m_length; i >= Position; i--) {
                Elem[i]=Elem[i-1]
            }
            Elem[Position - 1] = item;
            m_length++;
        }
        return OK;
    }
    int DeleteSqlList(int Position) {
        if (Position<1 || Position>m_length - 1) {
            return ERROR;
        }
        else {
            for (int i = Position; i < m_length; i++) {
                Elem[i - 1] = Elem[i];
            }
            m_length--;
        }
    }
    int LocateSqlList(T e) {
        for (int i = 0; i <= m_length - 1; i++) {
            if (Elem[i] == e) {
                return e;
                break;
            }
            else return ERROR;
        }
    }
    void DestorySqlList() {
        delete Elem[];
        m_length = 0;
        m_size = 0;
    }
    ~SqlList() {
        delete[]Elem;
    }
private:
    T* Elem;
    int m_length;
    int m_size;
};
int main() {
    SqlList<string> s(20);
    s.InsertSqlList(1, "a");
    cout << s[0] << endl;

    system("pause");

    return 0;
}

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值