-1

According to the article posted at http://wikistack.com/koenig-lookup-or-argument-dependent-lookup/ koenig look happens only in case of namespace. if it is true then how lookup happens in below case

#include<iostream>
using namespace std;

class foo {
public:
    friend void hello(foo obj) {
        cout << "hello\n";
    }
};

int main() {
    foo foo_obj;
    hello(foo_obj);
    return 0;
}
Jay Bhaskar
  • 157
  • 2
  • 11
  • Note that ADL is also applicable for class templates, not only namespaces, see example: [https://godbolt.org/z/rmYDXq](https://godbolt.org/z/rmYDXq). Though the case in the question is not ADL. – Amir Kirsh Jul 07 '20 at 14:59

1 Answers1

1

Making hello a friend of foo means that it's not actually a member of foo (despite its definition being inside of foo's definition). Its name is "injected" into the global namespace, which is how it's found inside of main.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111