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日

悬赏问题

  • ¥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数据集