Can we access the unnamed namespaces outside the file they were created?

  accessibility, c++, namespaces, scope

i was reading about namespace online and where i read the stuff about unnamed namespaces , there i
read that unnamed namespace are only accessible within the file they were created .but when i tried
it on my own it worked fine. how is that possible;
here is what i did.

file1:

#include<iostream>
using namespace std;
namespace space1 {
    int a = 10;
    void f() {
        cout << "in space1 of code 1" << endl;
    };
}
namespace {
    int x = 20;
    void f() {
        cout << "in unnamed space" << endl;
    }
}

file2: where i accessed the namespace from file1

#include<iostream>
#include "code1.cpp"
using namespace std;
int main() {
    space1::f();
    cout << space1::a;
    cout << x << endl;
    f();

    return 0;
}

Source: Windows Questions C++

LEAVE A COMMENT