Namespace and using

I work with Code::Blocks 16.01 on Win10.

Why is the last var equal to 10
if there is a line using namespace Jerry; before it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>

using namespace std;

namespace Tom {

    int var = 10;

}

namespace Jerry {

    int var = 1000;

}


int main()
{
    cout << "Tom::var = " << Tom::var << endl;
    cout << "Jerry::var = " << Jerry::var << endl << endl;

    using Tom::var;

    cout << "AFTER using Tom::var; --> var = " << var << endl << endl;

    using namespace Jerry;

    cout << "AFTER using namespace Jerry; --> var = " << var << endl << endl;

    return 0;
}
Tom::var = 10
Jerry::var = 1000

AFTER using Tom::var; --> var = 10

AFTER using namespace Jerry; --> var = 10


Process returned 0 (0x0)   execution time : 0.016 s
Press any key to continue.
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>

namespace Tom { int var = 10; }
namespace Jerry { int var = 1000; }

int main()
{
    std::cout << "Tom::var = " << Tom::var << std::endl;
    std::cout << "Jerry::var = " << Jerry::var << std::endl;
    
    return 0;
}


All this confirms that it saves a lot of trouble and wondering by forgetting about using namespace ...
Topic archived. No new replies allowed.