也许我对 C++ 不太了解,但我发现 C++ 编译器的行为难以理解(在我看来是危险的)。
MSVC、g++ 和 Clang 的行为相同。
问:为什么函数内部::a::f是可见的?fb::f(bool)
namespace a {
struct C {
bool value;
C(): value(false) {}
C(C const &): value(false) {}
explicit C(bool value): value(value) {}
};
inline C f(bool value) { return C(value); }
// why this function is visible as `f` inside `b::f(bool)`?
inline C f(C const &value) { return C(not value.value); }
}
namespace b {
inline bool f(::a::C const &value) { return value.value; }
inline bool f(bool …Run Code Online (Sandbox Code Playgroud)