Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code Blocks C++ Error expected primary expression before enum

Tags:

c++

I am self teaching myself in C++ so I just would like to ask for your forgiveness if my question is really basic.

I am following a tutorial on www.learncpp.com

According to the tutorial, I could define my c++ array such as like this

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?

like image 839
Mark Estrada Avatar asked Aug 26 '26 06:08

Mark Estrada


1 Answers

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
};
like image 69
Andreas DM Avatar answered Aug 28 '26 21:08

Andreas DM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!