A::C
只是一个类型别名,而别名是透明的。他们不“记得”他们来自哪里。当我们进行依赖于参数的查找并找出相关的命名空间是什么时,我们只考虑相关的命名空间。
类型
-不是我们的化名。不能只向现有类型添加关联的名称空间。的特定关联命名空间
f
(这是一种
std::vector<std::string>
)是吗
std
,它没有
operator<<
与之相关。既然没有
操作员<&书信电报;
使用普通查找找到,也没有使用ADL找到,调用失败。
现在,我说过不能只向现有类型添加关联的名称空间。但你当然可以创建新的类型:
namespace A {
struct C : std::vector<std::string> { };
}
或者:
namespace A {
// template parameters are also considered for associated namespaces
struct S : std::string { };
using C = std::vector<S>;
}