spandana
spandana

Reputation: 755

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_SESSION_MSG)
         return 0;
    }

Upvotes: 0

Views: 105

Answers (1)

Johannes Schaub - litb
Johannes Schaub - litb

Reputation: 506847

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++).

Upvotes: 8

Related Questions