Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何克服运行时检查失败#0问题?_C++_Runtime Error - Fatal编程技术网

C++ 如何克服运行时检查失败#0问题?

C++ 如何克服运行时检查失败#0问题?,c++,runtime-error,C++,Runtime Error,我对编码还不熟悉,不知道如何解决这个问题。 我得到的信息是: “运行时检查失败#0-ESP的值未在函数调用中正确保存。这通常是调用使用一种调用约定声明的函数,而函数指针使用另一种调用约定声明的结果。” 这项任务是为了帮助我们得到中国的生肖。 这是我的代码,可能不正确: #include <iostream> #include <assert.h> using namespace std; sign getZNum(int day, int month, int y

我对编码还不熟悉,不知道如何解决这个问题。 我得到的信息是: “运行时检查失败#0-ESP的值未在函数调用中正确保存。这通常是调用使用一种调用约定声明的函数,而函数指针使用另一种调用约定声明的结果。”

这项任务是为了帮助我们得到中国的生肖。 这是我的代码,可能不正确:

 #include <iostream>
#include <assert.h>
using namespace std;



sign getZNum(int day, int month, int year)
{
    int animalnum;
    enum sign { rat = 0, ox, tiger, rabbit, dragon, snake, horse, goat, monkey, rooster, dog, pig };
    sign animal;

    //figuring out if before or after feb so that I can make sure to bump down the year to the previous year 
    bool beforeFeb2;
    beforeFeb2 = false;
    if (!month > 2) {
        if (month != 2 || (month == 2 && day == 1)) {
            beforeFeb2 = true;
        }

    }
    // The first date is Feb 2, 1924.

    //calculating animalnum
    animalnum = ((year + beforeFeb2) - 1924) % 13;

    //assigning the animal based on animalnum
    switch (animalnum)
    {
    case 0:
        animal = rat;
        break;
    case 1:
        animal = ox;
        break;
    case 2:
        animal = tiger;
        break;
    case 3:
        animal = ox;
        break;
    case 4:
        break;
        animal = rabbit;
        break;
    case 5:
        animal = dragon;
        break;
    case 6:
        animal = snake;
        break;
    case 7:
        animal = horse;
        break;
    case 8:
        animal = goat;
        break;
    case 9:
        animal = monkey;
        break;
    case 10:
        animal = rooster;
        break;
    case 11:
        animal = dog;
        break;
    case 12:
        animal = pig;
        break;
    default: // code to be executed if n doesn't match any cases
        animal = rat;
    }
    cout<< animal;
   return animal;
}

//int getZNum(int, int , int ); 
int main() {

    getZNum(28, 10, 2001);
    return 0;
}
#包括
#包括
使用名称空间std;
签署getZNum(整数日、整数月、整数年)
{
国际动物组织;
枚举符号{鼠=0,牛,虎,兔,龙,蛇,马,山羊,猴,鸡,狗,猪};
符号动物;
//弄清楚是在2月之前还是之后,这样我就可以确保今年与前一年相比有所下降
在二月二日之前;
beforeb2=假;
如果(!月>2){
如果(月!=2 | |(月==2和日==1)){
beforeb2=真;
}
}
//第一天是1924年2月2日。
//计算动物数量
动物数量=((年+二月二日之前)-1924)%13;
//基于animalnum分配动物
开关(animalnum)
{
案例0:
动物=大鼠;
打破
案例1:
动物=牛;
打破
案例2:
动物=老虎;
打破
案例3:
动物=牛;
打破
案例4:
打破
动物=兔子;
打破
案例5:
动物=龙;
打破
案例6:
动物=蛇;
打破
案例7:
动物=马;
打破
案例8:
动物=山羊;
打破
案例9:
动物=猴子;
打破
案例10:
动物=公鸡;
打破
案例11:
动物=狗;
打破
案例12:
动物=猪;
打破
默认值://如果n不匹配任何情况,将执行的代码
动物=大鼠;
}

无论如何C++版本都是令人惊讶的编译。<代码>符号<代码>在返回类型< <代码> GETZNUM>代码>之后,不存在。如果你把它移到函数之外,会发生什么。如果你不想泄露它,它会在匿名命名空间中弹出。(!month>2)
。编译器将其视为
(!month>2
,这没有多大意义。如果(!(month>2)),是否要
?开关块可以替换为
符号动物=静态施法(animalnum);
我将顶部改为cassrt,并将“枚举符号”和“动物符号”放在函数之外。我还将顶部改为(!(月份>2))。感谢建议不要使用switch语句。