What happens when using namespace within a namespace?

Asked

Viewed 59 times

2

What happens when I use the directive using namespace x within a namespace?

For example:

namespace x {
int k = 1;
}

namespace y {
using namespace x;
}

Now when I use the namespace y can access settings from x too? This is:

namespace z {
int c = y::k;
}

1 answer

1


The second code works and will access the value of k. The using ends up being a kind of include within the scope, even if it does not function as #include, which even becomes less useful in C++20, since the latter brings the text and the using only allows reference.

Documentation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.