title: The ordering of namespace reference and includes affects compilation results
body: <p>I always think we should use namespace after includes, for example, we should use:</p>
  
  <pre><code>#include &lt;vector&gt;
  using std::vector; 
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>using std::vector;
  #include &lt;vector&gt;
  </code></pre>
  
  <p>but I find the second one is OK, what confuses me is that different ordering of them causes different results.See following simple example: here are two header files and one c++ file.</p>
  
  <pre><code>// test1.h
  #include &lt;vector&gt;
  
  using std::vector;
  #include "test2.h"
  
  // test2.h
  vector&lt;int&gt; v;
  
  // test.cpp
  #include "test1.h"
  
  int main()
  {
      return 0;
  }
  </code></pre>
  
  <p>Although test2.h doesn't include vector, but it compiles OK all above. 
  What's strange is when I swap the order of using std::vector; and #include , there happens a compile error like this:</p>
  
  <p>error C2143: syntax error : missing ';' before '&lt;'</p>
  
  <p>error C2501: 'vector' : missing storage-class or type specifiers</p>
  
  <p>error C2143: syntax error : missing ';' before '&lt;'</p>
  
  <p>error C2874: using-declaration causes a multiple declaration of 'vector'</p>
  
  <p>I do not understand the internals, does the order of namespace and includes really matter? why so this?</p>