error C2143: syntax error : missing ';' before 'class-head'

2024-05-06 03:32

本文主要是介绍error C2143: syntax error : missing ';' before 'class-head',希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

问题:

       关于error C2143: syntax error : missing ';' before '<class-head>' 这个错误及解决方法。

解释:

     这句话的意思就是在类的前面少加了“;”。

错误代码:

#include <iostream>
using namespace std;

#define maxsize 100
typedef int Datetype

class sequenlist
{
private:
    DateType data[maxsize];
    int len;
public:
    void initiate();
    int length();
    int insert(DateType x, int i);
    int delet(int i);
    int locate(DateType x);
    DateType get(int i);
};
void sequenlist::initiate()
{
    len = 0;
}
int sequenlist::length()
{
    return len;
}
int sequenlist::insert(DateType x, int i)
{
    int j;
    if (len >= maxsize) {
        cout << "overflow!\n";
        return 0;
    } else if ((i < 1) || (i > len + 1)) {
        cout << "position is not correct!\n";
        return 0;
    } else {
        for (j = len; j >= i; j--)
            data[j] = data[j - 1];
        len++;
        return 1;
    }
}
int sequenlist::delet(int i)
{
    int j;
    if ((i < 1) || (i > len)) {
        cout << "position is not corrcet!\n";
        return 0;
    } else {
        for (j = i; j < len; j++)
            data[j - 1] = data[j];
        len--;
        return 1;
  }
}
int sequenlist::locate(DateType x)
{
    int j = 0;
    while ((j < len) && (data[j] != x))
        j++;
    if (j < len)
        return j + 1;
    else
        return 0;
}
DateType sequenlist::get(int i)
{
    if ((i < 1) && (i > len))
        cout << "position is not correct!\n";
    else
        return data[i - 1];
}

int main()
{
 
    return 0;
}

 

 

改完后的代码:

 

#include <iostream>
using namespace std;

#define maxsize 100
typedef int DateType;

class sequenlist
{
private:
    DateType data[maxsize];
    int len;
public:
    void initiate();
    int length();
    int insert(DateType x, int i);
    int delet(int i);
    int locate(DateType x);
    DateType get(int i);
};
void sequenlist::initiate()
{
    len = 0;
}
int sequenlist::length()
{
    return len;
}
int sequenlist::insert(DateType x, int i)
{
    int j;
    if (len >= maxsize) {
        cout << "overflow!\n";
        return 0;
    } else if ((i < 1) || (i > len + 1)) {
        cout << "position is not correct!\n";
        return 0;
    } else {
        for (j = len; j >= i; j--)
            data[j] = data[j - 1];
        len++;
        return 1;
    }
}
int sequenlist::delet(int i)
{
    int j;
    if ((i < 1) || (i > len)) {
        cout << "position is not corrcet!\n";
        return 0;
    } else {
        for (j = i; j < len; j++)
            data[j - 1] = data[j];
        len--;
        return 1;
 }
}
int sequenlist::locate(DateType x)
{
    int j = 0;
    while ((j < len) && (data[j] !=x) )
        j++;
    if (j < len)
        return j + 1;
    else
        return 0;
}
DateType sequenlist::get(int i)
{
    if ((i < 1) && (i > len))
        cout << "position is not correct!\n";
    else
        return data[i - 1];
}

int main()
{
 
    return 0;
}

 

后续:

     好郁闷,我是看一本书的代码写的,typedef书上竟然没加分号,误导我,郁闷死了。

 

这篇关于error C2143: syntax error : missing ';' before 'class-head'的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/963337

相关文章

前端 CSS 动态设置样式::class、:style 等技巧(推荐)

《前端CSS动态设置样式::class、:style等技巧(推荐)》:本文主要介绍了Vue.js中动态绑定类名和内联样式的两种方法:对象语法和数组语法,通过对象语法,可以根据条件动态切换类名或样式;通过数组语法,可以同时绑定多个类名或样式,此外,还可以结合计算属性来生成复杂的类名或样式对象,详细内容请阅读本文,希望能对你有所帮助...

VUE动态绑定class类的三种常用方式及适用场景详解

《VUE动态绑定class类的三种常用方式及适用场景详解》文章介绍了在实际开发中动态绑定class的三种常见情况及其解决方案,包括根据不同的返回值渲染不同的class样式、给模块添加基础样式以及根据设... 目录前言1.动态选择class样式(对象添加:情景一)2.动态添加一个class样式(字符串添加:情

提示:Decompiled.class file,bytecode version如何解决

《提示:Decompiled.classfile,bytecodeversion如何解决》在处理Decompiled.classfile和bytecodeversion问题时,通过修改Maven配... 目录问题原因总结问题1、提示:Decompiled .class file,China编程 bytecode

类型信息:反射-Class

在说反射前提一个概念:RTTI(在运行时,识别一个对象的类型) public class Shapes {public static void main(String[] args) {List<Shape> shapes = Arrays.asList(new Circle(), new Square(), new Triangle());for (Shape shape : shapes

跟我一起玩《linux内核设计的艺术》第1章(四)——from setup.s to head.s,这回一定让main滚出来!(已解封)

看到书上1.3的大标题,以为马上就要见着main了,其实啊,还早着呢,光看setup.s和head.s的代码量就知道,跟bootsect.s没有可比性,真多……这确实需要包括我在内的大家多一些耐心,相信见着main后,大家的信心和干劲会上一个台阶,加油! 既然上篇已经玩转gdb,接下来的讲解肯定是边调试边分析书上的内容,纯理论讲解其实我并不在行。 setup.s: 目标:争取把setup.

react笔记 8-17 属性绑定 class绑定 引入图片 循环遍历

1、绑定属性 constructor(){super()this.state={name:"张三",title:'我是一个title'}}render() {return (<div><div>aaaaaaa{this.state.name}<div title={this.state.title}>我是一个title</div></div></div>)} 绑定属性直接使用花括号{}   注

编译linux内核出现 arm-eabi-gcc: error: : No such file or directory

external/e2fsprogs/lib/ext2fs/tdb.c:673:29: warning: comparison between : In function 'max2165_set_params': -。。。。。。。。。。。。。。。。。。 。。。。。。。。。。。。。 。。。。。。。。 host asm: libdvm <= dalvik/vm/mterp/out/Inte

收藏:解决 pip install 出现 error: subprocess-exited-with-error 错误的方法

在使用 pip 安装 Python 包时,有时候会遇到 error: subprocess-exited-with-error 错误。这种错误通常是由于 setuptools 版本问题引起的。本文将介绍如何解决这一问题 当你使用 pip install 安装某个 Python 包时,如果 setuptools 版本过高或过低,可能会导致安装过程出错,并出现类似以下错误信息:error: subpr

Nn criterions don’t compute the gradient w.r.t. targets error「pytorch」 (debug笔记)

Nn criterions don’t compute the gradient w.r.t. targets error「pytorch」 ##一、 缘由及解决方法 把这个pytorch-ddpg|github搬到jupyter notebook上运行时,出现错误Nn criterions don’t compute the gradient w.r.t. targets error。注:我用

src/pyaudio/device_api.c:9:10: fatal error: portaudio.h: 没有那个文件或目录

(venv) shgbitai@shgbitai-C9X299-PGF:~/pythonworkspace/ai-accompany$ pip install pyaudio sounddeviceCollecting pyaudioDownloading PyAudio-0.2.14.tar.gz (47 kB)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━