Skip to content

Instantly share code, notes, and snippets.

@robin92
Created November 22, 2016 08:26
Show Gist options
  • Save robin92/b46c171913962ec71bf7473a35e5c116 to your computer and use it in GitHub Desktop.
Save robin92/b46c171913962ec71bf7473a35e5c116 to your computer and use it in GitHub Desktop.
C++ ADL example
#include <iostream>
namespace other
{
struct Foo {};
void func(const Foo& foo) { std::cout << "yes!\n"; }
} // namespace other
struct Bar {};
void func(const Bar& bar) { std::cout << "no!\n"; }
int main(int, char**) {
// thanks to ADL it works
// func is used by unqualified name so ADL looks for a suitable element
func(other::Foo());
func(Bar());
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment