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

相关文章

#error用法

/* *检查编译此源文件的编译器是不是C++编译器 *如果使用的是C语言编译器则执行#error命令 *如果使用的是 C++ 编译器则跳过#error命令 */ #ifndef __cplusplus #error 亲,您当前使用的不是C++编译器噢! #endif #include <stdio.h> int main() {

brew install opencv@2 时报错 Error: Can't create update lock in /usr/local/var/homebrew/locks!

解决方案,报错里已经说明了: 我的解决方案: sudo chown -R "$USER":admin /usr/local   stackoverflow上的答案 I was able to solve the problem by using chown on the folder: sudo chown -R "$USER":admin /usr/local Also you'

BD错误集锦8——在集成Spring MVC + MyBtis编写mapper文件时需要注意格式 You have an error in your SQL syntax

报错的文件 <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.yuan.dao.YuanUserDao"><!

BD错误集锦3——ERROR: Can't get master address from ZooKeeper; znode data == null

hbase集群没启动,傻子!   启动集群 [s233 s234 s235]启动zk集群 $>zkServer.sh start $>zkServer.sh status   [s233] 启动dfs系统 $>start-dfs.sh 如果s237 namenode启动失败,则 [s237] $>hadoop-daemon.sh start namenode [s233]启动yarn集群

BD错误集锦1——[Hive]ERROR StatusLogger No log4j2 configuration file found. Using default configuration:

错误描述:在使用IDEA进行jdbc方式连接到hive数据仓库时,出现以下错误:                ERROR StatusLogger No log4j2 configuration file found. 问题原因:缺少log4j2.xml文件   <?xml version="1.0" encoding="UTF-8"?><Configuration><Appender

【鸿蒙】ERROR_GET_BUNDLE_INSTALLER_FAILED

错误信息 [ERROR_GET_BUNDLE_INSTALLER_FAILED] Troubleshooting guide $ hdc file send D:\Huawei\devEcoProjects\entry\build\default\outputs\default\entry-default-unsigned.hap /sdcard/e8a215ea7be1444197e6a58e

多头注意力机制(Multi-Head Attention)

文章目录 多头注意力机制的作用多头注意力机制的工作原理为什么使用多头注意力机制?代码示例 多头注意力机制(Multi-Head Attention)是Transformer架构中的一个核心组件。它在机器翻译、自然语言处理(NLP)等领域取得了显著的成功。多头注意力机制的引入是为了增强模型的能力,使其能够从不同的角度关注输入序列的不同部分,从而捕捉更多层次的信息。 多头注意力机

Class 对象在执行引擎中的初始化过程

一个 class 文件被加载到内存中需要经过 3 大步:装载、链接、初始化。 装载 装载是指 Java 虚拟机查找 .class 文件并生成字节流,然后根据字节流创建 java.lang.Class 对象的过程。 链接 链接过程分为 3 步:验证、准备、解析。 验证: 初始化 这是 class 加载的最后一步,这一阶段是执行类构造器方法的过程,并真正初始化类变量。 1.文件格式检验:检

QT 5.8.0 msvc_2015 64bit版本编译错误:-1: error: LNK1158: 无法运行“rc.exe”

一开始安装的时候我出现了另一种错误,换着D盘E盘装了几遍之后,出现了:-1: error: LNK1158: 无法运行“rc.exe”这个错误。 首先,我的系统是Windows10 1903版 64bit QT版本是 5.8.0  msvc_2015 64版 解决方法是将 C:\Program Files (x86)\Windows Kits\8.1\bin\x86\rc.exe, C:

关于 pnpm monorepo 项目中 TS2742 Error 的 workaround

最近我在使用 pnpm 作为包管理器开发一个 monorepo 项目,从个人体验来说,在 monorepo 项目中,pnpm 确实要比 yarn classic 用得舒心,最让我欣喜的是 pnpm 对 workspace 协议的支持度很好;另外感受比较明显的一点就是,开发过程中感知到的由于依赖层级导致的 bug 也变少了。 但是任何事情都不可能是完美的。果不其然,一个关键的 bug 就在等着我。