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

  • Home
  • SEARCH
  • 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 7883715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:36:27+00:00 2026-06-03T04:36:27+00:00

In "using namespace" statement inside an anonymous namespace it was asked whether the following

  • 0

In "using namespace" statement inside an anonymous namespace it was asked whether the following is legal

//file.cpp
//....
namespace
{
    using namespace std;
}

int a(){
 cout << "bla";
}

The answer was “It is”. Further, using namespace directives are generally despised even if inserted in cpp files since the scope differences between header and implementation files are not rock solid since the introduction of unity builds (https://stackoverflow.com/a/6474774/484230).

My question:
Does the anonymous namespace save me from such problems or can the using
directive still propagate file borders?
In https://stackoverflow.com/a/2577890/484230 a similar approach was proposed. Does it work for anonymous namespaces as well and is it really safe?
Of course std is a bad example but e.g. using namespace boost::assign; would be quite handy in some cpp files.

  • 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-03T04:36:28+00:00Added an answer on June 3, 2026 at 4:36 am

    There isn’t any difference between putting it in an anonymous namespace and putting it outside one. Either one produces the same effect, which is bringing the entire std namespace into your file’s top-level namespace. This isn’t good and it should be avoided.

    As for “propogating file borders”, it wouldn’t do that if you put it outside the anonymous namespace either. The only time it can infect other files is if it’s in a file that’s #included in other files, such as headers.

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

Sidebar

Related Questions

I am using the following code: #include <iostream> using namespace std; int main(int argc,
#include <iostream> #include <set> using namespace std; class StudentT { public: int id; string
I was using the "exit 1" statement in my Bash functions to terminate the
Using C++, an int gets converted from "signed" to "unsigned". Can I convert this
I am using the following code in JavaScript's document.write method: <script type="text/javascript"> document.write("<font color="blue">["+time()+"]</font>");
I have a SqlDependency set up using the following query: string sql = "SELECT
I am using following setting for customErrors in my web.config. <customErrors mode="On" defaultRedirect="GenericErrorPage.aspx" >
This code: Type.GetType("namespace.a.b.ClassName") returns null . I have in the usings: using namespace.a.b; The
i am using object of stringstream as follows: #include<iostream> #include <istream> using namespace std;
This following code gets this compile error: " invalid types 'int[int]' for array subscript

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.