컴파일러가 인수의 네임 스페이스를 고려합니다 (첫 번째 인수가 인수 종속적 룩업에 우선 함)? 또는 모호한 것으로 간주됩니까?
2
A
답변
7
모호합니다. 표준
For each argument type T in the function call, there is a set of zero or more associated namespaces
그래서 모두 네임 스페이스 Foo
과의 섹션 3.4.2에 따르면
prog.cpp: In function 'int main()':
prog.cpp:21:15: error: call of overloaded 'test(Foo::A&, Bar::B&, int)' is ambiguous test (a, b, 0);
^prog.cpp:10:7: note: candidate: void Foo::test(Foo::A&, Bar::B&, int) void test(A& , Bar::B&, int){} ^prog.cpp:16:7: note: candidate: void Bar::test(Foo::A&, Bar::B&, int) void test(Foo::A& , B&, int){}
2
:의 GCC에
namespace Bar
{
struct B;
}
namespace Foo
{
struct A{};
void test(A& , Bar::B&, int){}
}
namespace Bar
{
struct B{};
void test(Foo::A& , B&, int){}
}
int main() {
Foo::A a; Bar::B b;
test (a, b, 0);
return 0;
}
결과 : 과부하 세트는 두 개의 동등하게 유효한 오버로드를 포함 Bar
은 연관된 네임 스페이스 집합에 포함됩니다. 기능 test
이 둘 다에 있기 때문에 모호합니다.