Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7986109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:45:20+00:00 2026-06-04T11:45:20+00:00

Consider the following code: namespace C { class X {}; } namespace A {

  • 0

Consider the following code:

namespace C {
    class X {};
}

namespace A {
    class X {};

    namespace B {
        using namespace C;

        X x;
    }
}

I was expecting the type of x to be C::X due to the using namespace directive, but instead both VS2010 and online LLVM/Clang compiler resolve X within the namespace B to be A::X. Changing the using directive with a using declaration (using C::X), then it does resolve to C::X as expected.

The standard says on using directives [7.3.4.2]:

A using-directive specifies that the names in the nominated namespace can be used in the scope in which the using-directive appears after the using-directive. During unqualified name lookup (3.4.1), the names appear as if they were declared in the nearest enclosing namespace which contains both the using-directive and the nominated namespace.

My reading of this is that C::X should appear as if declared within namespace B, effectively hiding A::X. Which section(s) of the standard are behind this inconsistency between using directives and using declarations? Is there any way to hide a name from an outer scope by a using directive?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:45:23+00:00Added an answer on June 4, 2026 at 11:45 am

    The chapter on using directive seems to be somehow clear that you are seeing the expected behavior:

    7.3.4p2 A using-directive specifies that the names in the nominated namespace can be used in the scope in which the using-directive appears after the using-directive. During unqualified name lookup (3.4.1), the names appear as if they were declared in the nearest enclosing namespace which contains both the using-directive and the nominated namespace.

    7.3.4p3 A using-directive does not add any members to the declarative region in which it appears.

    That is, the using-directive adds the members of the namespace to the lookup set of the common namespace ancestor of the directive and the used namespace, not directly to the scope where the using-directive is used. This is explicitly stated in the second quote: it does not add any members to the declarative region of the using-directive.

    Later there is an example that is meant to illustrate something else but actually shows this:

    7.3.4p4 […] For another example

    namespace A {
      int i;
    }
    namespace B {
      int i;
      int j;
      namespace C {
        namespace D {
          using namespace A;
          int j;
          int k;
          int a = i; // B::i hides A::i
        }
    

    That last example is used to clarify transitivity (and contains more code), but it actually is equivalent to your code once you remove the extra code.

    So it seems that in your case, the using-directive is not hiding, but rather being hidden.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: using System; namespace ConsoleApplication2 { class Program { static void
Consider the following code: namespace DisposeTest { using System; class Program { static void
Consider the following code: #include <iostream> using namespace std; class Test { static int
Consider the following sample code: #include <iostream> using namespace std; class base { public:
Consider the following code: using System; using System.Runtime.InteropServices; namespace Demo { class Program {
Consider the following code: #include<iostream> using namespace std; class sample { int a; int
Consider the following sample code below: #include <iostream> using namespace std; class base {
Consider the following code: namespace ConsoleApplication { using NamespaceOne; using NamespaceTwo; class Program {
please consider following code #include <iostream> using namespace std; class Digit { private: int
Consider the following code: #include <iostream> #include <cstdio> #include <cstring> using namespace std; template<class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.