A bit more about C++ extern and const
We all know in order to make a const variable global we need to use extern both for the definition of this const variable and its declaration. That means, in file1.cpp we define the variable n in this way: extern const int n = 8; In file2.cpp we declare n in this way: extern const int n; So why do we need extern in file1.cpp when we define the const variable? It's because const implies internal linkage by default, so your "definition" isn't visible outside of the translation unit where it appears. In this case, by far the best solution is to put the declaration (extern int const n;) in a header file, and include that in both file1.cpp and file2.cpp. The linkage is determined by the first declaration the compiler sees(so become the header file), so the later definition in file1.cpp will have the correct (external) linkage. As an alternative solution, you add extern in both declare and define of the const, to make it external linkage.