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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:16:10+00:00 2026-06-03T01:16:10+00:00

Shouldn’t functions within a namespace only be accessible via using the namespace scoping or

  • 0

Shouldn’t functions within a namespace only be accessible via using the namespace scoping or by the using directive?

I am having a problem where certain functions, defined inside of a namespace, are accessible OUTSIDE of that namespace. I believe there should be a compiler error, but I am not getting one across the three different compilers I have tried (VS.NET 2003, VS2010 and GCC 4).

Here is the code:

namespace N{
  typedef struct _some_type *some_type;
  struct some_struct { int x; };
  void A(void);
  void B(int);
  void C(some_type*);
  void D(some_type);
  void E(struct some_struct);
}

using N::some_type;
using N::some_struct;

void TestFunction()
{
  some_type foo;
  some_struct s;

  N::A();         //should compile (and does on VS2003, VS2010, and GCC 4.1.2)
  ::A();          //shouldn't compile (and doesn't on VS2003, VS2010, and GCC 4.1.2)
  A();            //shouldn't compile (and doesn't on VS2003, VS2010, and GCC 4.1.2)

  N::B(0);        //should compile (and does on VS2003, VS2010, and GCC 4.1.2)
  ::B(0);         //shouldn't compile (and doesn't on VS2003, VS2010, and GCC 4.1.2)
  B(0);           //shouldn't compile (and doesn't on VS2003, VS2010, and GCC 4.1.2)

  N::C(&foo);     //should compile (and does on VS2003, VS2010, and GCC 4.1.2)
  ::C(&foo);      //shouldn't compile (and doesn't on VS2003, VS2010, and GCC 4.1.2)
  C(&foo);        //shouldn't compile (but does on VS2003, VS2010, and GCC 4.1.2) -- problem!

  N::D(foo);      //should compile (and does on VS2003, VS2010, and GCC 4.1.2)
  ::D(foo);       //shouldn't compile (and doesn't on VS2003, VS2010, and GCC 4.1.2)
  D(foo);         //shouldn't compile (but does on VS2003, VS2010, and GCC 4.1.2) -- problem!

  N::E(s);        //should compile (and does on VS2003, VS2010, and GCC 4.1.2)
  ::E(s);         //shouldn't compile (and doesn't on VS2003, VS2010, and GCC 4.1.2)
  E(s);           //shouldn't compile (but does on VS2003, VS2010, and GCC 4.1.2) -- problem!
}

None of the functions should be accessible without using the N:: prefix, but C, D, and E are for some unknown reason. I initially thought it was a compiler bug, but because I am seeing this across multiple compilers it makes me question what is going on.

  • 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-03T01:16:12+00:00Added an answer on June 3, 2026 at 1:16 am

    I think you’re seeing the effect of Koenig lookup. In your example, foo and s are types
    defined in namespace N. Your calls to routines C, D, and E use arguments of those types, so namespace N is searched in order to resolve those function calls.

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

Sidebar

Related Questions

Shouldn't I be able to call this CoffeeScript method from within an erb template?
I know I shouldn't be outputting things directly in PHP, but using a template
I shouldn't say I actually have a problem (the code seems to... work? Although
Why shouldn’t extern C be specified for a function that needs to be defined
We're building an app, our first using Rails 3, and we're having to build
Shouldn’t this definition be allowed in a lazy language like Haskell in which functions
Shouldn't the Log method block? namespace Sandbox { class Program { static void Main(string[]
I think this shouldn't be a big problem, but I can't find the solution
Shouldn't following command run myScript only at the runlevel 2. I noticed it executes
Why shouldn't one leave all methods and attributes accessible from anywhere (i.e. public )?

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.