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 8591231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:28:45+00:00 2026-06-11T23:28:45+00:00

From section 7.3.4.2 of the c++11 standard: A using-directive specifies that the names in

  • 0

From section 7.3.4.2 of the c++11 standard:

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. [
Note: In this context, “contains” means “contains directly or
indirectly”. —end note ]

What do the second and third sentences mean exactly? Please give example.

Here is the code I am attempting to understand:

namespace A
{
    int i = 7;
}
namespace B
{
    using namespace A;
    int i = i + 11;
}
int main(int argc, char * argv[])
{
    std::cout << A::i << " " << B::i << std::endl;
    return 0;
}

It print “7 7” and not “7 18” as I would expect.

Sorry for the typo, the program actually prints “7 11”.

  • 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-11T23:28:46+00:00Added an answer on June 11, 2026 at 11:28 pm

    Eliminating the undefined behaviour:

    namespace A
    {
        int i = 7;
    }
    namespace B
    {
        using namespace A;
        int tmp = i + 11;
        int i = tmp;
    }
    #include <iostream>
    int main()
    {
        std::cout << A::i << " " << B::i << std::endl;
        return 0;
    }
    

    The meaning of the standard is that at the line

        int tmp = i + 11;
    

    the name i appears in the “nearest enclosing namespace which contains both the using-directive and the nominated namespace“; the using-directive appears in namespace B while the nominated namespace is namespace A; the nearest enclosing namespace is the global namespace, so i appears as ::i. This means that if a name i is already present in the global namespace the code is ambiguous.

    For a more complex example:

    namespace A {
        namespace B {
            namespace C {
                int i = 4;
            }
        }
        namespace D {
            using namespace B::C;
            namespace E {
                int j = i;
            }
        }
    }
    

    At the line int j = i, i appears in the nearest enclosing namespace of the using-directive (i.e., A::D) and the nominated namespace (A::B::C), which is A. So, within A::D after the using-directive, and so also within A::D::E, the unqualified name i can refer to A::B::C::i appearing as A::i, shadowing any ::i, conflicting with any A::i, and being shadowed by any A::D::i or A::D::E::i (within A::D::E):

    int i = 1;                // shadowed by A::B::C::i appearing as A::i
    namespace A {
        int i = 2;            // conflicts with A::B::C::i appearing as A::i
        namespace B {
            int i = 3;        // irrelevant
            namespace C {
                int i = 4;    // nominated; appears as A::i
            }
        }
        namespace D {
            int i = 5;        // shadows A::B::C::i appearing as A::i
            using namespace B::C;
            namespace E {
                int i = 6;    // shadows A::B::C::i appearing as A::i
                int j = i;
            }
        }
    }
    

    Note that just because the name appears as A::i during unqualified name lookup, that does not mean that it actually is there; the qualified name A::i will continue to refer only to an actual name A::i (if any exists).

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

Sidebar

Related Questions

I follow example from here using section listview http://lalit3686.blogspot.com/2012/05/sectionadapter.html But how can I implement
I'm trying to build a section tag from the ground up using documentFragment(). It
quoting from The C++ Standard Library by N M Jousttis, Section 5.9 #include <
Our standard code section for using JDBC is... Connection conn = getConnection(...); Statement stmt
The section §3.9.1/6 from the C++ Standard says, Values of type bool are either
The MySQL documents state in section 11.5.3 that, despite what the SQL standard may
Is there any section in the C++ standard the shows that NULL references are
I have a NSFetchedResultsController which is fetching objects from a NSManagedObjectContext . I'm using
This is the code section from inno setup.My intention is to make two Checkbox
I'd like to use sed to collect the top section from a set of

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.