So I have this enum in a header file:

enum class ServoPort {PORT1 = 1, PORT2, PORT3, PORT4, PORT5, PORT6};

The trouble is that when I try to use it in the primary file (by doing MyClass::ServoPort::PORT1) I get a compile error:

exit status 1
expected unqualified-id before numeric constant

However, if I change the enum to be like so:

enum class ServoPort {PORT8 = 1, PORT9, PORT10, PORT11, PORT12, PORT13};

Then I do not get a compile error. What the heck? Can someone please shine some light on why this is happening?

  • Board: UNO R3
  • IDE: v1.8.5
  • Please add which Arduino board and IDE version. – Mikael Patel Feb 12 '19 at 20:54
  • If you are using an AVR based Arduino board it might be a conflict with the AVR header file pinsport.h. – Mikael Patel Feb 12 '19 at 20:55
  • @MikaelPatel done – You'reAGitForNotUsingGit Feb 12 '19 at 20:55
  • Please see the file: arduino-xxx/hardware/tools/avr/avr/include/avr/portpins.h. If you really want to use these symbols you could undef them in your header file. – Mikael Patel Feb 12 '19 at 20:57
  • 1
    The defines are pre-processed symbols before compiling. Your definition gives an illegal syntax when replaced. PORT1 = 1, PORT2, becomes, 1 = 1, 2. – Mikael Patel Feb 12 '19 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.