Skip to content
Go back

C++:ADLの一例

· Updated:
  • クラス内に定義されたものもADLで探せる:
    • friend関数にできるので、グローバルを汚染しなくて済む
namespace ns {
struct C {
    enum class E {};

    friend void foo(E);  // #1
};
void bar(C::E);  // #2
}  // namespace ns
void bar() {
    foo(ns::C::E{});  // OK: #1
    bar(ns::C::E{});  // OK: #2
    ns::foo(ns::C::E{});  // NG: friendは見えない
}