Linking with constant variable definition in a header file
<p>Suppose I created a header file constants.h and this file contains:</p>

<pre><code>extern const int YEAR = 2011; // definition
</code></pre>

<p>If I tried in a cpp file (MainCPP.cpp) to use this constant after declaring it without defining it and without including the constants.h file as following:</p>

<pre><code>extern const int YEAR; // declaration

int main() {
    cout &lt;&lt; YEAR &lt;&lt; endl;
}
</code></pre>

<p>When I try to do that I get: unresolved external symbol "int const YEAR". On the other hand, if I placed the definition of YEAR within constant.cpp file and done the same in MainCpp.cpp, I will not get the error and the linker will be able to link with YEAR defined within constants.cpp (without including constants.cpp in MainCpp.cpp here too).</p>

<p>Does this mean that the linker can link with source file code but not with header file code unless you explicitly included the header file.</p>
