There is one variable called BOT_TIME
that varies with the difficulty of my game, and hence isn't const
. There are many files that use it. I intend to use it as a global variable.
1) In constants.h
I declare it extern int BOT_TIME
.
In constants.cpp
, I declare it extern int BOT_TIME
.
BUILD => undefined references to the variable in all sources(Yes, I've included the header).
2) In constants.h
I declare it int BOT_TIME
.
In constants.cpp
, I declare it int BOT_TIME
.
Since non-consts
are by default extern
, I decided to leave that keyword.
BUILD => Multiple definition of the variable (shows in each source file that has constants.h included)
3) In constants.h
I declare it extern int BOT_TIME
.
In constants.cpp
, I declare it int BOT_TIME
.
This works.
Where is the issue?
Initializing the variable to something in constants.cpp
makes it work for cases 1 and 3.
What is this happening? Which is the right approach?