我的代码:
template <typename T>
void func(T v)
{
func2(v);
}
struct S {};
void func2(int) {}
void func2(S) {}
int main()
{
func(1); // error here
func(S{}); // OK
}
错误:
<source>: In instantiation of 'void func(T) [with T = int]':
<source>:14:9: required from here
14 | func(1); // error here
| ~~~~^~~
<source>:4:10: error: 'func2' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
4 | func2(v);
| ~~~~~^~~
<source>:10:6: note: 'void func2(S)' declared here, later in the translation unit
10 | void func2(S) {}
|
为什么查找func2
内置类型会失败,而查找用户定义的类型却会失败?