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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:37:44+00:00 2026-06-07T20:37:44+00:00

Ive been reading the Josuttis template book, and Ive been trying to put my

  • 0

Ive been reading the Josuttis template book, and Ive been trying to put my head around ADL. He says “ADL proceeds by looking up the name in namespaces and classes “assocaited with” the types of the call arguments”. Im just trying to see how it works looking up the name in a class. I put an example of my test below. I see how it looks up the name in a namespace.

class bryan_ns {
  public:
  class bryan {
    public:
      enum E { e1 };
      static void bryan_test() { std::cout << __PRETTY_FUNCTION__ << std::endl; }
  };

  void f(bryan::E) { std::cout << __PRETTY_FUNCTION__ << std::endl; }
};

void f(int)
{
  std::cout << "::f(int) called\n";
}


int main()
{
  f(bryan_ns::bryan::e1); // calls ::f(int)
}

But if I change bryan_ns to a namespace like so:

namespace bryan_ns {
  public:
  class bryan {
    public:
      enum E { e1 };
      static void bryan_test() { std::cout << __PRETTY_FUNCTION__ << std::endl; }
  };

  void f(bryan::E) { std::cout << __PRETTY_FUNCTION__ << std::endl; }
};

void f(int)
{
  std::cout << "::f(int) called\n";
}


int main()
{
  f(bryan_ns::bryan::e1); // calls bryan_ns::f(bryan::E)
}
  • 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-07T20:37:47+00:00Added an answer on June 7, 2026 at 8:37 pm

    ADL will look in the enclosing namespace of the type, and also inside the type itself. The best example is a friend function that is defined inside the type:

    namespace X {
    class test {
       friend void f( test ) { std::cout << "test" << std::endl; }
    };
    }
    int main() {
       X::test t;
       f( t );
    }
    

    The call to f(t) will find X::f whose declaration is only available inside the type test. This is a little known feature of friend function declarations: they declare a namespace level function, but provide the declaration only inside the type. A simple test to verify this behavior:

    namespace X {
       class test {
          friend void f( test );
       };
       //void f( test );          // [1]
    }
    void X::f( X::test ) {}       // [2]
    int main() {
       X::test t;
       f(t);                      // [3]
    }
    

    The definition in [2] will trigger a compilation error, as you can only define a function that has already been declared, and as [2] is outside of the namespace X that definition does not serve the purpose of self-declaration (if you define a function inside the namespace where it resides, then the definition is also a declaration, but not in this case). If we uncomment [1] the error would go away. Alternatively, if we comment [2], the code will compile indicating that for the call in [3], ADL has found the declaration inside the class.

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

Sidebar

Related Questions

Probably a very newbie question but, Ive been reading around and have found some
Hi all and thank you for reading... Ive been trying to find a fix
I'm trying to get a dylib working in my OSX project. Ive been reading
Ive been reading from several sources, and now Im more confused then ever. So
I've been reading a book on the cocos2d framework for ios5 for a few
I know this has been asked before as ive just been reading those answers
Ive been reading up on the latest version of the facebook sdk and Im
I've been reading on how to search LDAP servers using Python, but Ive been
i want to learn Expression blend.. ive been reading some blogs.. about it.. but
Ive been trying to figure out if multithreading in an io-bound application will actually

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.