0

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;
    }
0

1 Answer 1

8

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

Sign up to request clarification or add additional context in comments.

2 Comments

Schaub:Thanks...I did as like you told here.Got output within seconds for which i was breaking my head for hours.Thanks dude.
Schaub:I'm getting a warning after adding semicolon in the macro invocation as 'Declaration does not declare anything'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.