geza
geza

Reputation: 30010

Name hiding for declarations which made visible by a using-directive

[basic.scope.hiding]/4 says:

During the lookup of a name qualified by a namespace name, declarations that would otherwise be made visible by a using-directive can be hidden by declarations with the same name in the namespace containing the using-directive; see [namespace.qual].

I've failed the come up with an example, where [basic.scope.hiding]/4 actually in effect, and makes a difference (because other rules, like [namespace.udir]/2 already handles the situtation).

Can you give a simple (easy to understand) example of this rule?

Upvotes: 3

Views: 94

Answers (1)

rustyx
rustyx

Reputation: 85531

The difference is simply in qualified vs. unqualified lookup:

namespace A {
    int x;
    int y;
}

namespace B {
    using namespace A;
    int x;
    int test1() {
        return x + y; // [namespace.udir]/2
    }
}

int test2() {
    return B::x + B::y; // [basic.scope.hiding]/4
}

Upvotes: 1

Related Questions