C expression must have integral or enum type?

30,213

The code you've posted looks fine to me, and CodePad compiles it just fine in a quick little test.

So although the question doesn't mention it, I'm going to guess that you're working in Visual Studio.

In that case, it's very likely that the error you're seeing is an IntelliSense error, rather than an actual compiler error. Sometimes the IntelliSense engine (implemented using a different compiler) gets confused and reports errors that you've already fixed in the code. I notice this problem often when refactoring existing code.

The fix is to build/compile your project and verify that the error goes away. You should see a clean "Error List" window after a rebuild.

Share:
30,213
Levi H
Author by

Levi H

Updated on December 25, 2020

Comments

  • Levi H
    Levi H over 3 years

    So I've got this.

    #define MAX_MENU_OPTIONS 1
    
    typedef struct _NEW_MENU_OPTION
    {
        char* name;
        int type;
        char* opt1;
        int value1;
        int cycleid;
        int cycle_max;
        int cycle_min;
        int onenter;
    } NEW_MENU_OPTION;
    
    NEW_MENU_OPTION menu_options[MAX_MENU_OPTIONS];
    

    Then later in the code I have.

    switch(menu_options[menu_location].onenter)
    {
    case 0:
        break;
    }
    

    But I've got a red error thing on menu_options saying "Error: expression must have integral or enum type". I'm really confused and I can't see what's wrong, what is wrong?