lzx*_*zxp 5 c++ 64-bit operator-overloading language-lawyer operator-keyword
为什么 x64 没有歧义并且构建良好,而 x86 失败?在编译器资源管理器中,任何相同的 32/64 编译器都会给出类似的结果:
<source>(24): error C2666: 'arrs<int,5>::operator []': 2 overloads have similar conversions
<source>(6): note: could be 'T &arrs<T,5>::operator [](uint32_t)'
with
[
T=int
]
<source>(24): note: or 'built-in C++ operator[(T, int)'
with
[
T=int
]
<source>(24): note: while trying to match the argument list '(arrs<int,5>, int)'
Run Code Online (Sandbox Code Playgroud)
msvc x64/x86 https://godbolt.org/z/aavxj6
#include <cstdint>
template<class T, uint32_t N>
struct arrs
{
T& operator[](uint32_t i)
{
return v[i];
}
operator T* ()
{
return v;
}
T v[N];
};
int main()
{
arrs<int, 5> a;
a[0] = 0;
char x = 0;
}
Run Code Online (Sandbox Code Playgroud)