iso C++ n3290的要点:参数相关名称查找:第3.4.2节,第4段
When considering an associated namespace, the lookup is the same as the lookup
performed when the associated namespace is used as a qualifier (3.4.3.2) except
that:
— Any using-directives in the associated namespace are ignored.
— Any namespace-scope friend functions or **friend function templates** declared
in associated classes are visible within their respective namespaces even if
they are not visible during an ordinary lookup (11.3).
— All names except those of(possibly overloaded) functions and function
templates are ignored.在这里,当与2003年早些时候相比时,他增加了第三点。谁能用一个例子来解释...expalin是如何实现的……(重载)..
他还说,在第二点中,他包括了friend函数模板(我知道noraml称为friend函数),..can,任何人都可以解释这个,这就是显示的饱和度。
发布于 2011-07-28 17:47:03
我认为查找应该一直像这样工作,更多的是一种澄清,而不是实际的变化。我不确定添加它是否是因为在其他地方添加了一些需要更清楚地说明这一点的其他措辞,编译器在某些角落的情况下实际上是不同的,或者一些机构质疑什么是正确的实现。
广告点2。就像你可以声明函数f是类c的朋友一样,你也可以声明函数模板t是类c的朋友。声明是不同的,因为它明确地提到了模板参数,所以他们觉得两种情况都需要显式地适用。
template <typename T> bool f(T);
class c {
friend bool f<c>(c); // only particular instantiation is friend
template <typename T> friend bool f<T>(T); // all instantiations are friends
}(当然,您可以将其与作为模板本身的c结合使用,以获得无限乐趣)。
广告点3。该子句的意思是,如果在包含类f的名称空间n中查找函数f,则不考虑类f(而如果您编写n::f,它将获取类)。“可能超载”并不是真的必须存在。函数总是可以重载的,并且在所有命名空间中找到的所有重载都将包含在最终的重载解析中。
namespace n {
class c { ... };
class e { ... } f;
}
namespace o {
class d { ... };
void f(c &, d &) { ... };
void f(c &, d &, bool) { ... };
}
namespace p {
f(c(), d());
}f(c(), d())的关联命名空间既有n也有o。然而,n::f不是一个函数,而是一个(可能是函数器)实例,所以不考虑它(虽然旧的措辞允许考虑f的operator())。o::f是重载的,所有重载都被考虑在内(在收集了f的所有可能含义后,3参数变体被排除在外,因为只给出了2个参数)。
https://stackoverflow.com/questions/6856913
复制相似问题