[ACCEPTED]-Why does the order of my #includes matter? (C++)-include

Accepted answer
Score: 11

Generally speaking it should not, however 14 it may be possible for there to be conflicting 13 definitions of symbols or preprocessor macros 12 that end up confusing the compiler. Try 11 to narrow down the size of the problem by 10 removing pieces and includes from the conflicting 9 header until you can see what is causing 8 it.

In response to the error messages you 7 posted, the symbol NULL is often implemented 6 as a preprocessor macro for the number 0. This 5 is so that you can easily use it as a null 4 pointer. Therefore this:

list(const T& NULL);

Could be converted 3 into this syntax error by the preprocessor:

list(const T& 0);

Change 2 the name of the parameter to something other 1 than NULL.

Score: 3

Note that here:

Line 14: list(const T& NULL); (A constructor for "list" class)

NULL is the name of standard 8 macro - when a standard header file is included 7 before list_dec.h it will most likely cause 6 NULL to be defined which will in turn cause 5 your code to look something like this to 4 the compiler:

list(const T& 0);

The constant 0 above makes the 3 line ill-formed C++. You might get more 2 information by instructing your compiler 1 to produce preprocessed output file.

Score: 2

Presumably list_dec.h is running into a 4 macro that's defined in those other headers 3 (or some headers they in turn include) -- hard 2 to say which one without seeing the first 1 error message and the relevant part of list_dec.h!

Score: 2

The actual errors would give a more specific 5 clue, bt it means there's something in your 4 include file that is screwing up the scan 3 for the next one. The most common thing 2 would be some kind of unclude #-directive, like 1 a #if missing its #endif.

Score: 1

If the errors are random in nature, it could 5 be a missing semi colon. The compiler will 4 usually halt on that, but on occasion you 3 get "lucky".

Otherwise, conflicting names 2 or defines. Do you have anything named std 1 for example?

More Related questions