title: Use a function in different file and different namespace in Visual C++
body: <p>I am struggling with my first steps in C++. Already asked <a href="https://stackoverflow.com/questions/37680612/how-to-use-a-function-in-different-file-in-visual-c">this</a> question, but did not get the full answer specifically about namespace.</p>
  
  <p>I did the following.</p>
  
  <ol>
  <li>In Visual Studio 2015 created am empty project(New Project -> Visual C++ -> Empty Project)</li>
  <li>Then I added two files in Source.cpp and PrintFunc.cpp whose respective contents are as follows.</li>
  </ol>
  
  <p>Source.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int PrintHello();
  extern int tempCount;
  
  void main()
  {
      int i;
      PrintHello();
      cout &lt;&lt; tempCount &lt;&lt; endl;
      cout &lt;&lt; "Hello from main" &lt;&lt; endl;
  }
  </code></pre>
  
  <p>PrintFunc.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int tempCount = 111;
  
  int PrintHello()
  {
      cout &lt;&lt; "Hello from Source1" &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>This is compiling perfectly. 
  Now I am learning about namespaces, so I just tried to put the contents of the second file in a namespace as follows.</p>
  
  <p>PrintFunc.cpp (modified)</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  namespace MyNameSpace
  {
      int tempCount = 111;
  
      int PrintHello()
      {
          cout &lt;&lt; "Hello from Source1" &lt;&lt; endl;
          return 0;
      }
  }
  </code></pre>
  
  <p>And now I modified the Source.cpp also to reflect the namespaces introduction in the previous snippets.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int MyNameSpace::PrintHello();
  extern int MyNameSpace::tempCount;
  
  void main()
  {
      int i;
      PrintHello();
      cout &lt;&lt; tempCount &lt;&lt; endl;
      cout &lt;&lt; "Hello from main" &lt;&lt; endl;
  }
  </code></pre>
  
  <p>This simply does not compile. Can someone please kindly correct me. My objective is to understand namespace concept in c++. Also I have good exp with C#.</p>