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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:32:01+00:00 2026-05-31T17:32:01+00:00

The following source code compiles correctly with Visual Studio 2010: namespace NS { class

  • 0

The following source code compiles correctly with Visual Studio 2010:

namespace NS
   {
   class X
      {
      };   
   X Y(X str);
   } 

void myFun()
   {
   NS::X x;
   Y(x);
   }

(this is reduced code where all my own class and function names have been replaced by X, Y, …)

I would expect that the line Y(x) would fail to compile, since it should be NS::Y(x).

This source code is compiled with the following command

cl /c file.cpp

There are no other files included here, no other command line options.

Why does this file compile?
Bug in VS2010? Or something that I (and my 3 other colleagues) overlooked?

  • 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-31T17:32:02+00:00Added an answer on May 31, 2026 at 5:32 pm

    What you are experiencing is due to ADL (Argument Dependent Lookup).

    There is nothing wrong with your snippet (besides the fact that the linker will probably complain about NS::Y isn’t defined), but it should compile – VS2012 is handling the snippet as it should.

    The compiler will find NS::Y due to the fact that the type of parameter x (NS::X) is in the appropriate scope.


    3.4.2 Argument-dependent name lookup [basic.lookup.argdep]

    1. When an unqualified name is used as the postfix-expression in a
      function call (5.2.2), other namespaces not considered during the
      usual unqualified lookup (3.4.1) may be searched, and in those
      namespaces, namespace-scope friend function declarations (11.4) not
      otherwise visible may be found.

      These modifications to the search depend on the types of the
      arguments (and for template template arguments, the namespace of the
      template argument).

    2. For each argument type T in the function call, there is a set of zero or more associated namespaces and a set of zero or more
      associated classes to be considered.

      The sets of namespaces and
      classes is determined entirely by the types of the function arguments
      (and the namespace of any template template argument).

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

Sidebar

Related Questions

Visual Studio 2008 I am using the following source code that compiles ok using
The following source code alerts the following results: Internet Explorer 7 : 29 Firefox
I get the following compilation error with the following source code: Compilation Error: Type
I have the following SVG source code that generates a number of boxes with
I'm writing an XML file with the following code: Source source = new DOMSource(rootElement);
I have seen a web page source code containing the following css declaration at
Frequently I come across the following statements in C/C++ source code: $Id: lzio.c,v 1.24
I downloaded the qt embedded demo source code recently on my linux machine. Following
If we look at the latest jQuery source at http://code.jquery.com/jquery-latest.js we see the following:
With the following code: private Document transformDoc(Source source) throws TransformerException, IOException { TransformerFactory factory

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.