Why no ambiguity for x64 and builds fine, and fails for x86? In compiler explorer, any same 32/64 compilers give similar result:
<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)'
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;
}