开发者

getting errors with macros definition-c++

I am getting ClassID undeclared error in the following cpp code.

    #include "stdafx.h"
    #include <iostream>
    using namespace std;
    #define RM_SESSION_MSG 0x11
    #define DECLARE_RS232_MSG(ClassID)
    enum
    {
         ID=ClassID
    }

    int main()
    {
         DECLARE_RS232_MSG(RM开发者_JAVA技巧_SESSION_MSG)
         return 0;
    }


You are missing the line splice characters

#define DECLARE_RS232_MSG(ClassID) \
enum                               \
{                                  \
     ID=ClassID                    \
}

The line splice characters say that the current line and the next line are merged into a single line.

Without them, the macro definition ends at the end-of-line, so the enum in your code wasn't really part of the macro DECLARE_RS232_MSG.

You also miss a semicolon after the macro invocation in main (there needs to be a semicolon after each class or enumeration definition in C++).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜