小编Nic*_*hen的帖子

依赖于参数的查找通过模板类的基础

我有一个NB::B<T>NA::A命名空间中的非模板类派生的模板类.act<T>是模板函数add_ref在其模板参数的实例上调用函数.具体来说,act<NB::B<int>>想要使用ADL 找到add_refNB::Bbase 的名称空间中定义的内容.完整的例子如下:

template<class T>
void act() {
  T* p = 0;
  add_ref(p); // the failing line
}

namespace NA
{
  struct A { };

  // I want ADL to find this:
  void add_ref(A* p) {
  }
}

namespace NB
{
  // template class with non-template base
  template <class T>
  struct B: NA::A { };

  typedef B<int> Bi;

  // using NA::add_ref; // fixes the problem
} …
Run Code Online (Sandbox Code Playgroud)

c++ gcc templates clang argument-dependent-lookup

8
推荐指数
1
解决办法
706
查看次数

标签 统计

argument-dependent-lookup ×1

c++ ×1

clang ×1

gcc ×1

templates ×1