我有一个NB::B<T>从NA::A命名空间中的非模板类派生的模板类.act<T>是模板函数add_ref在其模板参数的实例上调用函数.具体来说,act<NB::B<int>>想要使用ADL 找到add_ref在NB::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)