namespace either undefined or redefined, why?
<p>just a very small program to test how to use the namespace. I divide it into 3 files, since in large product, ns.h is the namespace interface and ns.cpp is the implementation. I cannot put all these stuff into one file.</p>

<p>Here is the code:</p>

<pre><code>//ns.h
#ifndef MY_H
#define MY_H
namespace my
{
    int a=1;
    int b=0;
    void test();
}
#endif

//ns.cpp
#include &lt;iostream&gt;
#include "ns.h"

using namespace my;
//my::a=1;
//my::b=0;
void my::test()
{
    std::cout&lt;&lt;a&lt;&lt;std::endl;
}

//testns.cpp
#include &lt;iostream&gt;
#include "ns.h"
int main()
{
    std::cout&lt;&lt;my::b&lt;&lt;std::endl;
    my::test();
}
</code></pre>

<p>If I keep the above code, and compile will get:</p>

<pre><code>testns.obj : error LNK2005: "int my::b" (?b@my@@3HA) already defined in ns.obj
testns.obj : error LNK2005: "int my::a" (?a@my@@3HA) already defined in ns.obj
</code></pre>

<p>If I comment the statement #include "ns.h" I will get undefined error.</p>

<pre><code>D:\mfc\testns.cpp(5) : error C2653: 'my' : is not a class or namespace name
D:\mfc\testns.cpp(5) : error C2065: 'b' : undeclared identifier
D:\mfc\testns.cpp(6) : error C2653: 'my' : is not a class or namespace name
D:\mfc\testns.cpp(6) : error C2065: 'test' : undeclared identifier
</code></pre>

<p>Kindly help me if you know how to do this. Thanks a lot.</p>
