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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:04:12+00:00 2026-06-16T21:04:12+00:00

Some code I’ve been asked to modify looks rather like this: namespace XXX {

  • 0

Some code I’ve been asked to modify looks rather like this:

namespace XXX {

namespace {

// some stuff

} // end of unnamed

// Some stuff within the scope of XXX

} // end of XXX

I’m struggling to see the advantage, if any, of embedding the unnamed namespace within another namespace and I’m considering changing it to:

namespace {

// some stuff

} // end of unnamed

namespace XXX {

// Some stuff within the scope of XXX

} // end of XXX

Any views would be gratefully appreciated.

  • 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-16T21:04:13+00:00Added an answer on June 16, 2026 at 9:04 pm

    Okay, turns out that X::<anonymous>::foo() is visible as X::foo(). I’m surprised.

    So, no, there’s very little practical benefit. There may be semantic or documentation implications though.


    Original answer

    Well that rather depends on the "stuff", doesn’t it?

    The existing code allows code in X to have "private" other stuff that’s also in X but cannot be accessed from outside of X:

    #include <iostream>
    
    namespace X {
       namespace {
          void foo() { std::cout << "lol\n"; }
       }
       
       void bar() { foo(); }
    }
    
    int main()
    {
       X::bar();
       // X::foo();  // can't do this directly  [edit: turns out we can!]
    }
    
    • Output: lol\n

    Your proposed approach makes that "private stuff" available to the entire translation unit:

    #include <iostream>
    
    namespace {
       void foo() { std::cout << "lol\n"; }
    }
    
    namespace X {
       void bar() { foo(); }
    }
    
    int main()
    {
       X::bar();
       foo();     // works
    }
    
    • Output: lol\nlol\n
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In some code I've been reading, I've come across this : class Someclass {
So some code in MainApp.py goes like this, the lines I am concerned about
In some code I saw recently there was a structure defined like this: typedef
Given some code like this: class Json { } class Program { static void
In some code I am writing, sometimes I get ticks values like this Clear[z];
In some code that I read, there was an initializing statement like this char
Got some code that is not mine and its producing this warning atm: iehtmlwin.cpp(264)
Take some code like if (person.IsMale()) { doGuyStuff(); } else { doGirlStuff(); } Should
I some questions about some code I've been looking at. What does the @staticmethod
Some code I have requires the JCE unlimited Strength Policy Files. I'd like to

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.