C++ – Expected unqualified-id before numeric constant for defining a number

cc-preprocessorsyntax

I'm new to C++, so I don't know what they mean with this error in a phidget-code example:

Main.cpp:8:16: error: expected unqualified-id before numeric constant

//verander de volgende informatie naar de informatie voor jouw database

#define dserver "oege.ie.hva.nl"
#define duser "username"
#define dpassword "password"
#define ddatabase "databasename"

#define homeid 1234 //line 8

Is there a syntax error? Or something else? I use #define instead of int.

EDIT: added full error log..

complete error-log: http://pastebin.com/3vtbzmXD

Full main.cpp code: http://pastebin.com/SDTz8vni

Best Answer

The full error is

error: expected unqualified-id before numeric constant
 note: in expansion of macro ‘homeid’
string homeid;
       ^

You're trying to declare a variable with the same name as a macro, but that can't be done. The preprocessor has already stomped over the program, turning that into string 1234;, which is not a valid declaration. The preprocessor has no knowledge of the program structure, and macros don't follow the language's scope rules.

Where possible, use language features like constants and inline functions rather than macros. In this case, you might use

const int homeid = 1234;

This will be scoped in the global namespace, and can safely be hidden by something with the same name in a narrower scope. Even when hidden, it's always available as ::homeid.

When you really need a macro, it's wise to follow the convention of using SHOUTY_CAPS for macros. As well as drawing attention to the potential dangers and wierdnesses associated with macro use, it won't clash with any name using other capitalisation.