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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:21:55+00:00 2026-05-12T05:21:55+00:00

I was looking over some (C++) code and found something like this: //Foo.cpp namespace

  • 0

I was looking over some (C++) code and found something like this:

//Foo.cpp
namespace
{
    void SomeHelperFunctionA() {}
    void SomeHelperFunctionB() {}
    void SomeHelperFunctionC() {}

    //etc...    

    class SomeClass //<---
    {
        //Impl
    };
}

SomeHelperFunction[A-Z] are functions that are only needed in that translation unit, so I understand why they’re in an unnamed namespace. Similarly, SomeClass is also only required in that translation unit, but I was under the impression that you could have classes with identical names in different translation units without any sort of naming collisions provided that you didn’t have a global class declaration (e.g., in a commonly included header file).

I should also mention that this particular translation unit does not include any headers that might declare a class with an identical name (SomeClass).

So, given this information, could someone please shed some light on why the original programmer might have done this? Perhaps just as a precaution for the future?

I’ll be honest, I’ve never seen classes used in unnamed namespaces before.

  • 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-05-12T05:21:56+00:00Added an answer on May 12, 2026 at 5:21 am

    An anonymous namespace is like the static keyword when it is applied at the global level.

    An anonymous namespace makes it so you can’t call anything inside the namespace from another file.

    Anonymous namespaces allow you to limit the scope of what’s within to the current file only.

    The programmer would have done this to avoid naming conflicts. No global names will conflict in this way at linking time.

    Example:

    File: test.cpp

    namespace 
    {
      void A()
      {
      }
      void B()
      {
      }
      void C()
      {
      }
    }
    
    void CallABC()
    { 
      A();
      B();
      C();
    }
    

    File: main.cpp

    void CallABC();//You can use ABC from this file but not A, B and C
    
    void A()
    {
    //Do something different
    }
    
    int main(int argc, char** argv)
    {
      CallABC();
      A();//<--- calls the local file's A() not the other file. 
      return 0;
    }
    

    The above will compile fine. But if you tried to write an CallABC() function in your main you would have a linking error.

    In this way you can’t call A(), B() and C() functions individually, but you can call CallABC() that will call all of them one after the other.

    You can forward declare CallABC() inside your main.cpp and call it. But you can’t forward declare test.cpp’s A(), B() nor C() inside your main.cpp as you will have a linking error.

    As for why there is a class inside the namespace. It is to make sure no external files use this class. Something inside the .cpp probably uses that class.

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

Sidebar

Ask A Question

Stats

  • Questions 341k
  • Answers 341k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer first try this/ css: div.blabla input.links {display: block;...} try that… May 14, 2026 at 4:57 am
  • Editorial Team
    Editorial Team added an answer Why did they do it this way? Every Integer between… May 14, 2026 at 4:57 am
  • Editorial Team
    Editorial Team added an answer This question has been asked today: How can I highlight… May 14, 2026 at 4:57 am

Related Questions

How do I convert an image into a buffer so that I can send
I've been looking over the following VB code: http://www.codeproject.com/KB/vb/toggleNetworkConn.aspx If you look under The
In my VC++ application I have an embedded browser (MSHTML). It works fine and
Disclaimer Yes, I am fully aware that what I am asking about is totally

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.