Consider the following scenario:
MyFile.cpp:
const int myVar = 0; // global variable
AnotherFile.cpp:
void myFun() { std::cout << myVar;
Now, if I add extern const int myVar; in AnotherFile.cpp before use, the linker complains how
Unauthorized External
I can move myVar declaration to MyFile.h and include MyFile.h in AnotherFile.cpp to solve the problem. But I do not want to move the declaration to the header file. Is there any other way I can do this work?
source share