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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:20:36+00:00 2026-06-18T10:20:36+00:00

This is follow up question from Does argument dependent lookup only search namespaces or

  • 0

This is follow up question from Does argument dependent lookup only search namespaces or classes too? , In which @David Rodríguez said “ADL will look in the enclosing namespace of the type, and also inside the type itself” . I may have got him wrong what he tried to say but I was trying this example:

struct foo{
    static void bar(foo* z){}    
};

int main(){
    foo* z;
    bar(z);
}

It doesn’t compiles, producing the error ” ‘bar’ was not declared in this scope ” . Is it the case that ADL doesn’t considers the static member function?. I mean in the example associated class is foo so wouldn’t ADL look inside the class? . Can anyone please simplify the rules here?

  • 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-18T10:20:37+00:00Added an answer on June 18, 2026 at 10:20 am

    He probably meant this:

    struct foo{
        friend void bar(foo* z){}    //not static, its friend now
    };
    
    foo* z;
    bar(z); //fine now
    

    But then technically bar() is not inside foo. It is still in the enclosing namespace of foo.

    —

    EDIT:

    He indeed meant friend, as he said (emphasis mine):

    The best example is a friend function that is defined inside the type

    And his example illustrates further. Probably you need to read “defined inside”, rather than only “inside”.

    The word “defined” is all that makes the difference, because it looks like the function’s name bar is introduced into the scope of the class, but in actuality, the name bar is introduced into the enclosing namespace of foo (see §3.3.1/3-4 and §11.3/6).

    Here is a better example:

    namespace Demo
    {
         struct foo
         {
           friend void bar(foo* z){}
         };
    }
    
    foo *z;
    bar(z); //foo (type of z) is inside Demo, so is bar
            //(even though bar is defined inside foo!)
    
    bar(NULL);    //error - NULL doesn't help ADL.
    bar(nullptr); //error - nullptr doesn't help ADL.
    
    bar(static<foo*>(NULL)); //ok - ADL
    

    Note that the name bar, even though is introduced into the namespace Demo, is hidden, and thus cannot be used from outside using usual name-lookup:

    using namespace Demo; //brings ALL (visible) names from Demo to current scope
    
    bar(NULL); //STILL error - means bar is invisible
    

    Or,

    Demo::bar(NULL);       //error - not found
    Demo::foo::bar(NULL);  //error - not found
    

    Hope that helps.

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

Sidebar

Related Questions

This is a follow-on from this question, in which I was trying to suppress
Disclaimer: This is a follow-on question from my other question about NServiceBus which was
This is a follow up question from Calling constructor in return statement . This
This is a follow-on question from the one I asked here . Can constraints
This is a follow up from a question of mine that was just answered
This is a follow up from my previous question I have this code basically
This is a follow-on from a previous SO question Anchoring CSS Repeating Background Image
This is a follow on from my previous question although this is about something
This question is a follow on from this one ... I am binding to
This is a follow-up to a question I'd asked earlier which phrased this as

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.