3

3 つの例があります。

私。

typedef int foo;

namespace B
{
    struct S
    {
        operator int(){ return 24; }
    };
        int foo(B::S s){ return 0; }
}

int main()
{
    int t=foo(B::S()); //24, ADL does not apply
}

Ⅱ.

namespace B
{
    struct S
    {
        operator int(){ return 24; }
    };
        int foo(B::S s){ return 0; }
}

int main()
{
    int t=foo(B::S()); //0, ADL applies
}

III.

namespace B
{
    struct S
    {
        operator int(){ return 24; }
    };
        int foo(B::S s){ return 0; }
}
int foo(B::S s){ return 12; }

int main()
{
    int t=foo(B::S()); //error: call of overloaded ‘foo(B::S)’ is ambiguous
                       //ADL applies
}

ADL ルックアップが適用される実際の条件は何ですか? 記載されている標準を参照する必要があります。

4

2 に答える 2

2

この標準の段落は明確になり、最初の例と非常によく似た例さえあります。

3.4.1/3:

関数呼び出しの後置式として使用される非修飾名のルックアップは、3.4.2 [basic.lookup.argdep] で説明されています。[注:式が関数呼び出しの後置式であるかどうかを (解析中に) 判断するために、通常の名前検索規則が適用されます。3.4.2 の規則は、式の構文解釈には影響しません。例えば、

typedef int f;
namespace N {
  struct A {
    friend void f(A &);
    operator int();
    void g(A a) {
      int i = f(a);    // f is the typedef, not the friend
                       // function: equivalent to int(a)
    }
  };
}

式は関数呼び出しではないため、引数依存の名前検索 (3.4.2) は適用されず、フレンド関数fは見つかりません。-終了注記

于 2014-05-30T16:08:45.083 に答える