If a CPP source file is including multiple .h - will the order will be to include first .h do its text substitutions and then include 2nd?
I'm getting error
g++ main.cpp -o production.out
In file included from map.h:11,
from main.cpp:1:
player.h: In function ‘int read_input(player*)’:
player.h:59:46: error: ‘WIDTH’ was not declared in this scope
59 | if (key=='d' && player_->position[X]<WIDTH-1) {
| ^~~~~
player.h:59:46: note: the macro ‘WIDTH’ had not yet been defined
In file included from main.cpp:1:
map.h:15: note: it was later defined here
15 | #define WIDTH 5
|
In file included from map.h:11,
from main.cpp:1:
player.h:68:53: error: ‘HEIGHT’ was not declared in this scope
68 | else if (key == 's' && player_->position[Y]<HEIGHT-1) {
| ^~~~~~
player.h:68:53: note: the macro ‘HEIGHT’ had not yet been defined
In file included from main.cpp:1:
map.h:16: note: it was later defined here
16 | #define HEIGHT 5
|
make: *** [makefile:6: production] Error 1```
main.cpp is including first map.h then player.h
player.h
```cpp
#ifndef PLAYER_H
#define PLAYER_H
//#define DEBUG - Use compiler flag -D instead
#include <cstdint>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include "map.h"
#include "constants.h"
/* Player Position */
#define X 0
#define Y 1
struct player {
std::uint16_t position[2];
int symbol;
};
...
#endif /*PLAYER_H*/
map.h
#ifndef MAP_H
#define MAP_H
#define clear_screen() write(STDOUT_FILENO, "\033[2J\033[H", 7);
#include <iostream>
#include <cstdint>
#include <unistd.h>
#include "debug.h"
#include "player.h"
/* MAP DIMENSIONS */
#define WIDTH 5
#define HEIGHT 5
/* BLOCKS */
#define WALL 0
#define WALKABLE 1
#define PLAYER 2
struct map {
std::int16_t data[HEIGHT][WIDTH] = {0};
};
...
#endif /*MAP_H*/