什么是关于什么参数依赖查找的好解释?很多人也称它为Koenig Lookup.
我最好知道:
这段代码应该如何表现?如果我在函数中使用限定名称,它会调用泛型函数忽略我的重载call_read(); 如果我使用非限定名称,它首先调用重载然后调用泛型版本.有什么不同?这是海湾合作委员会的一个错误吗?
#include <iostream>
struct info1 {};
struct info2 {};
template<class T> void read(T& x)
{
std::cout << "generic" << std::endl;
}
template<class T> void call_read(T& x)
{
::read(x); // if I replace ::read(x) with read(x) the overload is called
}
void read(info1& x)
{
std::cout << "overload" << std::endl;
}
int main()
{
info1 x;
info2 y;
call_read(x);
call_read(y);
}
Run Code Online (Sandbox Code Playgroud)
我也注意到它对基本类型有所不同.请参阅下面的代码
#include <iostream>
typedef struct info1 {};
typedef struct info2 {};
typedef int …Run Code Online (Sandbox Code Playgroud) c++ lookup templates language-lawyer argument-dependent-lookup