如果有一个会发生什么?
Foo::test(Foo::A &a, Bar::B &b, C &c);
和一个
Bar::test(Foo::A &a, Bar::B &b, C &c);
。
是编译器按顺序考虑参数的名称空间(第一个参数优先于参数依赖查找),还是被认为是模棱两可的?
这将是模棱两可的。重载集包含两个同等有效的重载:
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;
}
在gcc中的结果:
prog.cpp:在函数'int main()'中:
prog.cpp:21:15:错误:重载的'test(Foo :: A&,Bar :: B&,int)'的调用是含糊的测试(a,b, 0);
^ prog.cpp:10:7:注意:候选项:void Foo :: test(Foo :: A&,Bar :: B&,int)void test(A&,Bar :: B&,int){} ^ prog.cpp: 16:7:注意:候选者:void Bar :: test(Foo :: A&,Bar :: B&,int)void test(Foo :: A&,B&,int){}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句