困扰我的代码发布在这里:
namespace ns1 {
struct myStruct1 {};
struct myStruct2 {};
}
namespace ns2 {
template <typename T>
constexpr int foo(T& x) {
return 1;
}
// If the two functions below are switched, it returns 2 correctly
template <typename T>
constexpr int fooCaller(T& x) {
return foo(x);
}
constexpr int foo(ns1::myStruct2& x) {
return 2;
}
}
// If the below is uncommented, it also returns 2 correctly
/*
namespace ns1 {
constexpr int foo(myStruct2& x) {
return 2;
} …Run Code Online (Sandbox Code Playgroud)