elfighting 2021-09-22 22:05 采纳率: 50%
浏览 47
已结题

【c++构造函数】请问为什么报错啊?

似乎是构造函数不对,但是看不出来哪里不对。

****head.h****
#include<iostream>
template<class type>
class seqlist {
public:
    seqlist(int size){
        maxsize = size;
        length = 0;
        start = new type[maxsize];
    }
    seqlist(std::istream& in) { read(in); }
    ~seqlist() { delete[]start; }
    std::istream& read(std::istream&);
    void simplify();
    void cancel(int);
    void output(std::ostream&);
private:
    type* start;
    int maxsize, length;
};

**head.cpp**
#include"head.h"
#include<iostream>
using namespace std;
template<class type> istream& seqlist<type>::read(istream& in) {
    cout << "please input the length of the list:";
    in >> maxsize;
    start = new type[maxsize];
    type x;
    length = 0;
    while (in >> x) {
        *start++ = x;
        length++;
    }
    return in;
}
template<class type> void seqlist<type>::cancel(int i) {
    for (; i < length - 1; i++)
        start[i] = start[i + 1];
}

template<class type> void seqlist<type>::simplify() {
    for(int i=0;i<length;i++)
        for (int j = i + 1; j < length; j++) {
            if (start[i] == start[j])
                cancel(j);
        }
}

template<class type> void seqlist<type>::output(ostream& out) {
    for (int i = 0; i < length; i++)
        out << start[i] << " ";
}

**main.cpp**
#include"head.h"
#include<iostream>
using namespace std;
int main() {
    seqlist<int> data(cin);
    data.simplify();
    data.output(cout);
}
  • 写回答

2条回答 默认 最新

  • CSDN专家-link 2021-09-22 22:11
    关注

    给出了什麽错误提示信息啊?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 10月1日
  • 已采纳回答 9月23日
  • 创建了问题 9月22日

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么