Does alias namespace change?

From my understanding, global variables in a file .cppget an external connection. Suppose there are two source files: a.cppand b.cpp:

// a.cpp
namespace a_ns
{
  int foo;
}

// b.cpp
namespace b_ns
{
  int foo;
}

Now suppose that both are eligible after namespace ns=a_ns;and namespace ns=b_ns;respectively. Will it trigger any behavior undefined The, as it would be (I think), if both a.cppand b.cppuse the same namespace nsfor foo?

+4
source share
2 answers

foo, , .. a_ns::foo b_ns::foo. , , undefined - , foo, bar.

, , , . Confer - ++), namespace-names , namespace aliases :

7.3.2

. , ....

, namespace ns=a_ns, a.cpp, "" a.cpp, namespace ns=b_ns, b.cpp, "" b.cpp. ns::foo a_ns a.cpp b_ns b.cpp .

foo , . namespace ns { int foo; } a.cpp b.cpp, .cpp , , . duplicate symbol __ZN2ns3fooE in: ../a.o; ../b.o.

+3

. , a_ns::foo b_ns::foo, .

+5

Source: https://habr.com/ru/post/1688375/


All Articles