title: When 'inline' must be specified explicitly to a definition of namespace?
body: <p>from C++ primer 5th ed. chapter 18: inline namespaces:</p>
  <p>An inline namespace is a new feature of namespace added by the new standard , it allows to use the member names of that namespace in the enclosing scope without the need to fully-qualify them. e.g:</p>
  <pre><code>inline namespace n{
      int x = 9;
  }
  
  namespace n{ // implicitly inline
      int y = x;
  }
  
  int z = x;
  
  int main(int argc, char* argv[]){
  
      std::cout &lt;&lt; x &lt;&lt; ' ' &lt;&lt; y &lt;&lt; ' ' &lt;&lt; z &lt;&lt; '\n';
  
      std::cout &lt;&lt; '\n';
  }
  </code></pre>
  <ul>
  <li><p>Until here it is OK. What makes me wander is: If I have a namespace that is defined as a dis-contiguous namespace (from several parts, each part in its relevant header/source like <code>std</code>). And I want to define my namespace as <code>inline</code> thus should each header adds to this namespace defines it <code>inline</code> too?</p>
  <pre><code>// foo.h
  inline namespace ns{
      void foo();
  }
  
  // foo.cpp
  #include &lt;iostream&gt;
  #include &quot;foo.h&quot;
  
  void ns::foo(){
      std::cout &lt;&lt; &quot;ns::foo()\n&quot;;
  }
  
  // bar.h
  
  namespace ns{
      void bar();
  }
  
  // bar.cpp
  #include &lt;iostream&gt;
  #include &quot;bar.h&quot;
  
  void ns::bar(){
      std::cout &lt;&lt; &quot;ns::bar()\n&quot;;
  }
  
  // main.cpp
  
  #include &lt;iostream&gt;
  #include &quot;foo.h&quot; // defines ns as inline
  #include &quot;bar.h&quot; // opens ns. ns is implicitly inline
  
  // #include &quot;bar.h&quot; // defines ns as non-inline
  // #include &quot;foo.h&quot; // opens ns. tries to define ns as inline. Error
  
  
  
  int main(int argc, char* argv[]){
  
      foo(); // ok
      bar(); // ok
  
      std::cout &lt;&lt; '\n';
  }
  
  
      std::cout &lt;&lt; '\n';
  }
  </code></pre>
  </li>
  <li><p>The code works fine but it fails to work if I reverse the inclusion of headers <code>foo.h</code> and <code>bar.h</code>; because if I include <code>bar.h</code> first, it defines <code>ns</code> as non-inline then including <code>foo.h</code> will define it as <code>inline</code>, this header Opens the namespace. The compiler fails because <code>inline</code> must be specified to first definition of the namespace so <code>bar.h</code> needs to define it as <code>inline</code> too. So I always need to include 'foo.h' first. Thus only 'foo.h' defines it inline and other header define it as non-inline. But it is not always the case that we need to use 'foo.h' after all defining it <code>inline</code> in a single part makes the code inconsistent. Why should I include a header that I don't need its names? After all thinking that it is inline makes me and clients of my library trying to uses names from it without qualifying it thinking it is defined <code>inline</code>.</p>
  </li>
  <li><p>Is <code>inline</code> necessary to all the definitions of a dis-contiguous namespace residing in multiple header/source files if one of them specified it?</p>
  </li>
  </ul>
  <p>Should each header define the same namespace as <code>inline</code>?</p>