enum declaration isn't working

Enum is declared in a .h, compiler says it's not declared in this scope. I tried defining in the .ino itself and then separately in a .h with the same results. Currently display.ino is the only file that menu.h is included in.

// display.ino
#include "menu.h"

void updateDisplayMode(Mode mode)
{
}

// menu.h
#ifndef MODE_H
#define MODE_H

enum Mode {Automatic, Manual, Development};

#endif /* MODE_H */

Compiler errors:

display:103: error: variable or field 'updateDisplayMode' declared void

void updateDisplayMode(Mode mode)

^

display:103: error: 'Mode' was not declared in this scope

exit status 1
variable or field 'updateDisplayMode' declared void

Try:

// menu.h
#ifndef MODE_H
#define MODE_H

enum Mode {Automatic, Manual, Development};

#endif /* MODE_H */

void updateDisplayMode(Mode mode)
{
}

larryd:
Try:

// menu.h

#ifndef MODE_H
#define MODE_H

enum Mode {Automatic, Manual, Development};

#endif /* MODE_H */

void updateDisplayMode(Mode mode)
{
}

I did this (moved my function to within the .h file) and it compiles although this isn’t what I’m trying to accomplish. I prefer to leave my code in the .ino and declare the enum at the top via the include. This is a pretty standard c programming construct but it seems as if it’s not working within the arduino environment?

Thanks for your help!

// menu.h
#ifndef MODE_H
#define MODE_H

enum Mode {Automatic, Manual, Development};

#endif /* MODE_H */

By convention the name of the file and the include guards are the same.

Look at the cpp file that the IDE creates from your ino file. It has created function prototypes for you. Where? THAT is the key. Before the header file is included guarantees that Mode will not be defined at that point. You can generate your own function prototypes, and put them anywhere that you want. Some places, obviously, work better than others.

PaulS:
By convention the name of the file and the include guards are the same.

Look at the cpp file that the IDE creates from your ino file. It has created function prototypes for you. Where? THAT is the key. Before the header file is included guarantees that Mode will not be defined at that point. You can generate your own function prototypes, and put them anywhere that you want. Some places, obviously, work better than others.

The guards was a brainfart by me. You explained it perfectly here, thanks. I didn't think about the fact that the automatically created declarations would appear before this .ino tab altogether in the .cpp, I added an explicit declaration at the start of this .ino just below the #include and that cleared it up.

Thanks again.