C++ 错误:在c+;中返回前应为非限定id+;

C++ 错误:在c+;中返回前应为非限定id+;,c++,C++,当我想要编译时,我得到: 问题:在“return”之前应为非限定id 返回0; 关于最后一行: erreur:expexted在{token之前声明 我没有修改代码,只是修改了中间部分…有什么问题??? 这是我的密码: #包括 使用名称空间std; int main() { 库特 您忘记了此if语句的结尾大括号,因此后续的else if被视为语法错误。您需要在if语句体完成后添加大括号: if (chapeau) { cout << "le Professeur Viole

当我想要编译时,我得到: 问题:在“return”之前应为非限定id 返回0; 关于最后一行: erreur:expexted在{token之前声明

我没有修改代码,只是修改了中间部分…有什么问题??? 这是我的密码:


#包括
使用名称空间std;
int main()
{
库特
您忘记了此
if
语句的结尾大括号,因此后续的
else if
被视为语法错误。您需要在
if
语句体完成后添加大括号:

if (chapeau) {
    cout << "le Professeur Violet";
}
else if (moustaches) {
    cout << "le Colonel Moutarde";
}
// ...
if(起首部分){
cout您需要将“
}
”移动到
cout建议行之前:

  • 使用一致的3-4空格缩进,您会发现这些问题更容易解决
  • 使用垂直排列{}的大括号样式,您将很快看到这些问题
  • 始终将控制块缩进另一个级别
  • 使用语法突出显示编辑器,这很有帮助,稍后您将感谢我
比如说,

type
functionname( arguments )
{
    if (something)
    {
        do stuff
    }
    else
    {
        do other stuff
    }
    switch (value)
    {
        case 'a':
            astuff
            break;
        case 'b':
            bstuff
            //fallthrough //always comment fallthrough as intentional
        case 'c':
            break;
        default: //always consider default, and handle it explicitly
            break;
    }
    while ( the lights are on )
    {
        if ( something happened )
        {
            run around in circles
            if ( you are scared ) //yeah, much more than 3-4 levels of indent are too many!
            {
                scream and shout
            }
        }
    }
    return typevalue; //always return something, you'll thank me later
}

只是为了那些为了同样的原因来到这里的人们:

不要使用保留关键字

我在类定义delete()中命名了一个函数,它是一个保留关键字,不应用作函数名。将其重命名为deletion()(在我的例子中,这在语义上也有意义)解决了这个问题

有关保留关键字的列表:

我引述:
“由于语言使用了这些关键字,因此无法重新定义或重载这些关键字。”

thx但我在最后两行仍然出现错误:返回0;}返回错误前预期的非限定id:返回错误前预期的声明{tokencheck my answer,您的问题是,
}
未定位。@user2774480初始
if
语句的结束大括号仍在
else if
行的末尾。请删除该大括号,错误应消失。@user2774480在最后一个
else
之后,必须删除另一个结束大括号
,才能使错误消失。你看到了吗?啊,好的,我看到了很多,现在它工作了。。该死,这太蠢了;)
if (chapeau) {
    cout << "le Professeur Violet";
}
else if (moustaches) {
    cout << "le Colonel Moutarde";
}
// ...
type
functionname( arguments )
{
    if (something)
    {
        do stuff
    }
    else
    {
        do other stuff
    }
    switch (value)
    {
        case 'a':
            astuff
            break;
        case 'b':
            bstuff
            //fallthrough //always comment fallthrough as intentional
        case 'c':
            break;
        default: //always consider default, and handle it explicitly
            break;
    }
    while ( the lights are on )
    {
        if ( something happened )
        {
            run around in circles
            if ( you are scared ) //yeah, much more than 3-4 levels of indent are too many!
            {
                scream and shout
            }
        }
    }
    return typevalue; //always return something, you'll thank me later
}