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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:28:42+00:00 2026-05-25T17:28:42+00:00

For practice, I wrote some template functions whose names are the same as the

  • 0

For practice, I wrote some template functions whose names are the same as the stl algorithms. But my code can not compile

error: Call to < algorithm_name > is ambiguous.

I only included using std::necessary_names; in my code rather than using namespace std;.

  • 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-25T17:28:42+00:00Added an answer on May 25, 2026 at 5:28 pm

    Usually when you have using, the “used” name takes precedence:

    namespace N { int x = 0; }
    int x = 1;
    
    int main() {
       using N::x;
       cout << x;
    }
    
    // Output: 0
    

    However, Argument-Dependent Lookup can mess this up:

    namespace N {
       struct T {};
       void f(T) {}
    }
    
    namespace M {
        void f(N::T) {}
    }
    
    int main() {
       using M::f;
       N::T o;
       f(o);       // <--- error: call of overloaded 'f(N::T&)' is ambiguous
    }
    

    So, if you are having trouble, qualify your own namespace (in this example, M) explicitly:

    namespace N {
       struct T {};
       void f(T)     { cout << "N::f"; }
    }
    
    namespace M {
        void f(N::T) { cout << "M::f"; }
    }
    
    int main() {
       using M::f;
       N::T o;
       M::f(o);    // <--- Output: "M::f"
    }
    

    In a somewhat bizarre twist, you can also use parentheses to prevent ADL:

    namespace N {
       struct T {};
       void f(T)     { cout << "N::f"; }
    }
    
    namespace M {
        void f(N::T) { cout << "M::f"; }
    }
    
    int main() {
       using M::f;
       N::T o;
       (f)(o);     // <--- Output: "M::f"
    }
    

    Explanation

    [n3290: 3.4.1/1]: [re: unqualified name lookup] In all the cases
    listed in 3.4.1, the scopes are searched for a declaration in the
    order listed in each of the respective categories; name lookup ends
    as soon as a declaration is found for the name
    . If no declaration is
    found, the program is ill-formed.

    [n3290: 3.4.1/2]: [i.e. first priority] The declarations from the
    namespace nominated by a using-directive become visible in a namespace
    enclosing the using-directive; see 7.3.4. For the purpose of the
    unqualified name lookup rules described in 3.4.1, the declarations
    from the namespace nominated by the using-directive are considered
    members of that enclosing namespace.

    [n3290: 3.4.2/1]: [re: argument-dependent lookup] When the postfix-expression in a function call
    (5.2.2) is an unqualified-id, 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.3) 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).

    i.e. Normal lookup stops at the name that you brought into scope with using, but when ADL comes into play, other names are also added to the candidate set, causing an ambiguity between two names.

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

Sidebar

Related Questions

I wrote program to convert decimal to binary for practice purposes but i get
I am cleaning up some code in a C# app that I wrote and
I wrote some code to connect the application to it's database, then I created
I'm looking at some code examples on powershellpro.com and don't understand why he wrote
I wrote some code in C and I was surprised to see it take
I just wrote some JavaScript code that follows along with what I believe to
During practice of customizing VirtualPathProvider, I found that it the custom VirtualPathProvider can be
Best practice is to use unique ivs, but what is unique? Is it unique
I'm trying to practice myself with custom class loaders, and I've some questions. Is
I wrote some sql scripts to create a database and store data. I just

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.