名稱查詢和訪問檢查

名稱查詢發生過載解析度。這意味著如果失去名稱查詢,則不會通過過載決策選擇更好匹配的函式:

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