C++ 基本类型和用户定义类型的名称查找问题

C++ 基本类型和用户定义类型的名称查找问题,c++,templates,language-lawyer,argument-dependent-lookup,name-lookup,C++,Templates,Language Lawyer,Argument Dependent Lookup,Name Lookup,这包括: struct type{}; template<typename T> void foo(T in) { bar(in, type()); } void bar(int, const type&) {} int main() { foo(42); } 结构类型{}; 模板 void foo(T in){bar(in,type());} 空条(int,const type&){} int main(){foo(42);} 但事实并非如此(正如我在我的报告中所了

这包括:

struct type{};

template<typename T>
void foo(T in) { bar(in, type()); }

void bar(int, const type&) {}
int main() { foo(42); }
结构类型{};
模板
void foo(T in){bar(in,type());}
空条(int,const type&){}
int main(){foo(42);}
但事实并非如此(正如我在我的报告中所了解的):

模板
void foo(T in){bar(in);}
空条(int){}
int main(){foo(42);}
第一个代码段编译的原因也用ADL解释了吗?如果是,怎么做


模板参数是一种基本类型,ADL不应该为其工作。。。为什么使用类型
type
会有什么不同?

尽管在您的具体专业中,中的
是基本类型,
bar
仍然是一个依赖名称,因此它的查找依赖于参数的部分是在实例化上下文中执行的。使其依赖的参数没有关联的名称空间这一事实与此无关。所有非依赖参数仍会对关联的名称空间和类集起作用。

尽管在具体的专业化中,
中的
是基本类型,
条仍然是依赖名称,因此其查找中依赖参数的部分是在实例化上下文中执行的。使其依赖的参数没有关联的名称空间这一事实与此无关。所有非依赖参数仍会对关联的名称空间和类集作出贡献

template<typename T>
void foo(T in) { bar(in); }

void bar(int) {}
int main() { foo(42); }