名称查找和访问检查
名称查找后发生重载分辨率。这意味着如果失去名称查找,则不会通过重载决策选择更好匹配的函数:
void f(int x);
struct S {
void f(double x);
void g() { f(42); } // calls S::f because global f is not visible here,
// even though it would be a better match
};
在访问检查之前发生过载分辨率。如果匹配比可访问函数更好,则可以通过重载决策选择不可访问的函数。
class C {
public:
static void f(double x);
private:
static void f(int x);
};
C::f(42); // Error! Calls private C::f(int) even though public C::f(double) is viable.
类似地,重载解析发生时不检查结果调用是否与 explicit
有关:
struct X {
explicit X(int );
X(char );
};
void foo(X );
foo({4}); // X(int) is better much, but expression is
// ill-formed because selected constructor is explicit