I listed my two questions below with C++ code. Thank you in advance.
(1) Using "extern" fails to find outside static symbols. Why?
config.cpp
static int config_id = 123;
run.cpp
extern int config_id;
void exec() {
int id = config_id; // "config_id" symbol not found!!!
// It works when config_id in config.cpp is not static.
}
(2) If int config_id = 123
is in a namespace namespace app
, how to correctly reference it?
config.cpp
namespace app {
int config_id = 123;
}
run.cpp
using namespace app;
extern int config_id; // Fail to refer to the symbol in config.app.
// How to fix?