C++ Compiler parses source file before header file erratically
<p>When I change a header file, which contains a template class definition, my compiler (the one that ships with VS2015) first parses the source file where the class is instantiated, and only then the header file. This results in an incorrect binary. </p>

<p>However, if I change the header file again and compile, the parsing order is correct (header first, source after), and the resulting binary does the right job.</p>

<p>The order in which the compiler parses the file can be seen in the Build output window and I have no parallel or multi-processor compilation options enabled.</p>

<p>I can reproduce this with 100% success rate. Am I doing something wrong, is there something I could change?</p>

<p>The code is below.</p>

<p>Class.h</p>

<pre><code>template&lt;class T&gt; class Class {
    void foo () {
        WriteToFile("A");
    }
</code></pre>

<p>Usage.cpp</p>

<pre><code>Class* c = new C();
c-&gt;foo();
</code></pre>

<p>Full build/rebuild. Output in file: A.</p>

<p>Step 1:</p>

<p>add the following line to <code>foo()</code>: <code>WriteToFile("B");</code>
Compile: order of output: Usage.cpp, Class.h
Output in file: A</p>

<p>Step 2:</p>

<p>add to following line to <code>foo()</code>: <code>WriteToFile("C")</code>;`
Compile: order of output: Class.h, Usage.cpp
Output in file: A B C</p>

<p>Go on until forever, same behavior.</p>

<p>Note: I simply hit F7 to "Build", after a full rebuild it works fine, but it takes a long time.</p>