功能模板查找问题 [英] Function template look-up issue

查看:71
本文介绍了功能模板查找问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以在编译时解释为什么以下代码给出错误(错误C2065:'select':未声明的标识符):

 namespace N 
{
class MyClass
{
};

模板< int I> void select(MyClass *)
{
}
}

void g(N :: MyClass * mp)
{
select< 10 -10(熔点);
}

void main()
{
}





我正在读一本书。根据Argument依赖查找规则,这应该工作正常,因为我在g`s参数中指定了'N ::'。因此,select()应该对编译器可见。

解决方案

select函数是命名空间N的一部分。因此你应该通过
引用它。

 N :: select< 10> (mp); 


参见竞争对手为什么ADL找不到函数模板?在堆栈溢出 [ ^ ]。

Could someone please explain why the following code is giving error (error C2065: 'select' : undeclared identifier) at compile time:

namespace N 
{ 
  class MyClass 
  { 
  };

  template<int I> void select(MyClass*)
  {
  }
}

void g (N::MyClass* mp) 
{ 
  select<10>(mp); 
}

void main()
{
}



I was reading a book. According to Argument dependent look-up rule, this should work fine, since i have specified 'N::' in g`s argument. So, "select()" should be visible to the compiler.

解决方案

The select function is part of namespace N. Hence you should reference it by

N::select<10> (mp);


See The Competitors: "Why doesn't ADL find function templates?" at Stack Overflow[^].


这篇关于功能模板查找问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆