计算机小混子 2022-09-30 23:53 采纳率: 100%
浏览 21
已结题

macos的vscode报错这是怎么回事?

macos的vscode报错这是怎么回事?

SeqList.h
const int MaxSize = 100;
template <class T>
class seqlist
{
public:
    SeqList();//构造函数
    SeqList(T a[],int n);//带参构造函数
    int GetLength();//获取顺序表的长度
    T Get(int i);//获取顺序表的值
    int Locate(T x);//定位x在顺序表中的位置
    void Insert(int i,T x);//将x插入顺序表中的i位置
    T Delete(int i);//删除第i个位置的元素
    void PrintList();         // 顺序表的遍历(输出)
    void Union(SeqList<T> S1);  // 将有序顺序表S1合并到当前有序顺序表中
private:
    T data[MaxSize];//顺序表
    int length;//顺序表的长度
};

seqlist.cpp
#include "seqlist.h"
template <class T>
//无参构造函数
SeqList<T>::SeqList()
{
    length = 0;
}

//有参构造函数
template<class T>
SeqList<T>::SeqList(T a[],int n)
{
    if(n>MaxSize) throw "参数非法";
    for (i = 0;i<n;i++)
        data[i] = a[i];
    length = n;
}

//插入
template<class T>
void SeqList<T>::Insert(int i,T x)
{
    if(length>=MaxSize)throw"上溢出";
    if(i<1||i>length+1)throw"位置不对";//length+1因为这是顺序表
    for(j = length;j>=i;j--)
        data[j] = data[j-1];
    data[j-1] = x;
    length++;
}

//删除
template<class T>
T SeqList<T>::Delete(int i)
{
    if(length==0) throw "位置错误!";
    T x = data[i-1];//先把要删除的元素存进x
    for(j=i;j<length;j++)//后面的元素向前覆盖一个位置
    {
        data[i-1]=data[i];
    }
    length--;
    rerturn 0;
}

//按位查找
template<class T>
T SeqList<T>::Get(int i)
{
    if(i<0||i>length) throw "位置错误";
    return data[i-1];//返回查找到的元素
}

//按值查找
template <class T>
int SeqList<T>::Locate(T x)
{
    for(i = 0;i<length;i++)
        if(data[i]==x)return i+1;//返回逻辑序号
    return 0;
}
//顺序表的遍历
template<class T>
void SeqList<T>::PrintList()
{
    for(int i = 0;i<length;i++)
        cout<<data[i]<<" ";
    cout<<endl;
}
//将有序顺序表S1合并到当前有序顺序表中
template<class T>
void SeqList<T>::Union(SeqList<T> S1)
{
    
}
main.cpp
#include <iostream>
#include "seqlist.h"
using namespace std;
int main()
{
    int a[]={12,21,3,15,8,16};
    SeqList<int> L1;
    SeqList<int> L2(a,6);
    try            // 有异常抛出throw的函数调用要放在try-catch中
    {  L1.Insert(1,10);
    cout<< "顺序表1的第1个元素是: "<<L1.Get(1)<<endl;
    L2.Insert(8,10);
    cout<< "顺序表2的第4个元素是: "<<L2.Get(4)<<endl;
    }
    catch(const char * msg) {  cout<<msg<<endl;  } //输出捕获到的异常信息
    return  0;
}
#include <iostream>
#include "seqlist.h"
using namespace std;
int main()
{
    int a[]={12,21,3,15,8,16};
    SeqList<int> L1;
    SeqList<int> L2(a,6);
    try            // 有异常抛出throw的函数调用要放在try-catch中
    {  L1.Insert(1,10);
    cout<< "顺序表1的第1个元素是: "<<L1.Get(1)<<endl;
    L2.Insert(8,10);
    cout<< "顺序表2的第4个元素是: "<<L2.Get(4)<<endl;
    }
    catch(const char * msg) {  cout<<msg<<endl;  } //输出捕获到的异常信息
    return  0;
}


![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/541421355466180.png "#left")
截屏2022-09-30 23.48.30.png
  • 写回答

1条回答 默认 最新

  • 浪客 2022-10-01 00:05
    关注

    你这是多个cpp文件编译,需要在task.json的agrs里指定参与编译的文件名。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 10月12日
  • 已采纳回答 10月4日
  • 创建了问题 9月30日

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装