朋友功能模板查找

时间:2016-06-20 02:19:33

标签: c++ argument-dependent-lookup friend-function function-templates

根据标准,在类中声明和定义的友元函数只能由ADL查找。所以,我认为以下代码应该编译。

template<int M>
struct test{
    template<int N = 0>
    friend void foo(test){}
};

int main(){
    test<2> t;
    foo(t);// compile
    foo<1>(t);// error
}

但是,gcc会出现以下错误:

main.cpp: In function 'int main()':

main.cpp:10:5: error: 'foo' was not declared in this scope

     foo<1>(t);

     ^~~

然后,我有三个问题。

  1. 是否应根据标准找到template<int N> foo
  2. 为什么foo找不到foo<1>
  3. 除了定义foo外?
  4. 之外是否有解决方法?

0 个答案:

没有答案