Вопрос

I am writing a serial library using boost and I have an enum:

enum parity_t { PARITY_NONE, PARITY_ODD, PARITY_EVEN };

I get errors like:

Error 1 error C2059: syntax error : '('

I couldn't figure out what the issue was. Then my friend and I tried:

void PARITY_NONE();

And we got these errors:

Error 1 error C2143: syntax error : missing ')' before 'constant'

Error 2 error C2143: syntax error : missing ';' before 'constant'

Error 3 error C2182: 'WORD' : illegal use of type 'void'

Error 4 error C2059: syntax error : ')'

I am including boost asio, which I figure is including the Windows serial api somewhere. This only occurs in Windows. As a work around I have changed my enumeration names. I cannot, however, find anything related to this issue on the internet. Can someone help us figure this out?

Это было полезно?

Решение

It's defined in winbase.h:

//
// Settable Stop and Parity bits.
//

#define STOPBITS_10       ((WORD)0x0001)
#define STOPBITS_15       ((WORD)0x0002)
#define STOPBITS_20       ((WORD)0x0004)
#define PARITY_NONE       ((WORD)0x0100)
#define PARITY_ODD        ((WORD)0x0200)
#define PARITY_EVEN       ((WORD)0x0400)
#define PARITY_MARK       ((WORD)0x0800)
#define PARITY_SPACE      ((WORD)0x1000)

#undef them before creating your enum.

Другие советы

It's defined in WinBase.h:

//
// Settable Stop and Parity bits.
//

#define STOPBITS_10       ((WORD)0x0001)
#define STOPBITS_15       ((WORD)0x0002)
#define STOPBITS_20       ((WORD)0x0004)
#define PARITY_NONE       ((WORD)0x0100)
#define PARITY_ODD        ((WORD)0x0200)
#define PARITY_EVEN       ((WORD)0x0400)
#define PARITY_MARK       ((WORD)0x0800)
#define PARITY_SPACE      ((WORD)0x1000)

Might aswell use their values, as they would work the same as your enum if you don't use that enum for indexing an array or the likes.

What's most likely happening here is one of the values in your enum is already #define to a different value. The expansion of that value is causing the enum to issue a compiler error. You can verify this by changing the code to the following

#ifdef PARITY_NONE
#error Duplicate definition
#endif

Repeat for every value in the enum

Discovering where the definition is coming from is a bit trickier. If you're lucky the following will work

  • Comment out your enum definition
  • Type PARITY_NONE in a method
  • Right click and select "Go To Definition"
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top