Both traditional header guards and
#pragma once
accomplish the same thing, which is to prevent including the same
declarations multiple times in the same module.
However, neither will protect you from including the same
definitions in multiple modules, which is what you've done.
Lines 10-17 in constants.h are
defining variables. Therefore, if you include constants.h in multiple modules, you will have multiple definitions of these variables at link time, which is what the linker is complining about.
You should never
define variables in a header file.
What you should do is
declare the variables in the header.
In constants.h:
1 2 3
|
#pragma once
extern const int WINDOW_WIDTH;
.. etc
|
Then in one and only one of your .cpp files:
1 2
|
const int WINDOW_WIDTH = 800; // specify window width
|