Created
November 22, 2016 08:26
-
-
Save robin92/b46c171913962ec71bf7473a35e5c116 to your computer and use it in GitHub Desktop.
C++ ADL example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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