简体   繁体   English

代码块C ++错误预期在枚举之前的主表达式

[英]Code Blocks C++ Error expected primary expression before enum

I am self teaching myself in C++ so I just would like to ask for your forgiveness if my question is really basic. 我是用C ++自学的,所以如果我的问题非常基本,我想请求你的原谅。

I am following a tutorial on www.learncpp.com 我正在关注www.learncpp.com上的教程

According to the tutorial, I could define my c++ array such as like this 根据教程,我可以像这样定义我的c ++数组

int main()
{
    using namespace std;
    enum ArrayElements
    {
        MAX_ARRAY_SIZE = 5;
    };

    int anArray[MAX_ARRAY_SIZE];
    return 0;
}

But codeblock keep on issuing error 但是代码块继续发出错误

||=== Build: Debug in CH6 (compiler: GNU GCC Compiler) ===|
In function 'int main()':|
|6|error: expected primary-expression before 'enum'|
error: expected ';' before 'enum'|
||=== Build failed: 2 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|

I just dont know what is causing the error or is there a problem with the tutorial I am following? 我只是不知道导致错误的是什么,或者我正在关注的教程是否存在问题?

Remove the semicolon inside the enum. 删除枚举中的分号。

MAX_ARRAY_SIZE = 5;
   //             ^

If you do have more names inside the enum, separate them with a comma , 如果枚举中有更多名称,请用逗号分隔,

enum COLOR
{
    RED,
    BLUE,
    GREEN
};

使用以下代码替换enum ArrayElements块:MAX_ARRAY_SIZE = 5;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM