#include <stdio.h>
#include <cstddef>
#include <cstring>
namespace /*namespace name generated by compiler*/
{
struct BB{};
}
struct AA{};
namespace my
{
inline void * memcpy(void*, const void*, std::size_t)
{
puts("CUSTOM IMPLEMENTATION");
return 0;
}
}
namespace my
{
void func()
{
AA a;
memcpy(&a, &a, sizeof(a)); // ambigious call for g++4.7 - g++6.2
BB b;
memcpy(&b, &b, sizeof(b)); // unambigious call
}
}
int main(int, char **)
{
my::func();
return 0;
}
为什么的memcpy是ambigious通话吗?不合格查找
请参考ANSI ISO IEC 14882,C++ 2003,3.4.1,(6)(第30页)中变量“i”的示例。它“证明”在这样的建设中没有任何不安。
namespace A {
namespace N {
void f();
}
}
void A::N::f() {
i = 5;
// The following scopes are searched for a declaration of i:
// 1) outermost block scope of A::N::f, before the use of i
// 2) scope of namespace N
// 3) scope of namespace A
// 4) global scope, before the definition of A::N::f
}
是不合格的查找规则在GCC中被破坏还是我不明白?
您能否包含C++ 2003的示例,第30页。 3.4.1,(6)? – user463035818
更好地发布这里的例子。 – CinCout
如果您希望我们引用语言标准的某个特定部分,那么如果您引用*标准的相关部分将会更有帮助。 –