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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:41:41+00:00 2026-05-10T17:41:41+00:00

A feature of C++ is the ability to create unnamed (anonymous) namespaces, like so:

  • 0

A feature of C++ is the ability to create unnamed (anonymous) namespaces, like so:

namespace {     int cannotAccessOutsideThisFile() { ... } } // namespace 

You would think that such a feature would be useless — since you can’t specify the name of the namespace, it’s impossible to access anything within it from outside. But these unnamed namespaces are accessible within the file they’re created in, as if you had an implicit using-clause to them.

My question is, why or when would this be preferable to using static functions? Or are they essentially two ways of doing the exact same thing?

  • 1 1 Answer
  • 2 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. 2026-05-10T17:41:42+00:00Added an answer on May 10, 2026 at 5:41 pm

    The C++ Standard reads in section 7.3.1.1 Unnamed namespaces, paragraph 2:

    The use of the static keyword is deprecated when declaring objects in a namespace scope, the unnamed-namespace provides a superior alternative.

    Static only applies to names of objects, functions, and anonymous unions, not to type declarations.

    Edit:

    The decision to deprecate this use of the static keyword (affecting visibility of a variable declaration in a translation unit) has been reversed (ref). In this case using a static or an unnamed namespace are back to being essentially two ways of doing the exact same thing. For more discussion please see this SO question.

    Unnamed namespace‘s still have the advantage of allowing you to define translation-unit-local types. Please see this SO question for more details.

    Credit goes to Mike Percy for bringing this to my attention.

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

Sidebar

Related Questions

I am trying to implement a paging feature using PDO's ability to create cursors.
I'm wondering if Python has anything like the C# anonymous classes feature. To clarify,
I am a beginner at database design and I would like to create a
I am new to programming on the Android and would like to create an
How to design a database that supports a feature that would allow the application
Some of the features I think it must include are: Print Entire Solution Ability
A feature in Eclipse that I really miss is how you can auto-complete method
Windows has a feature that allows an administrator to perform auto-logon whenever it is
Anyone know this compiler feature? It seems GCC support that. How does it work?
I'm currently using Visual Studio 2010 Professional, and noticed the ability to create Word

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.