c++ error: operator []: overloads have similar conversions

template <class Type>
class Array
{
    Type&       operator[] ( unsigned int index );
}

Array<int> a1;
a1.pushback(10);
a1.pushback(20);

int g = a1[1];

c++ error: operator []:  3 overloads have similar conversions

Because the compiler can't determine "1" is int, const int, or unsigned int in the implicit conversion rule.

We need to cast it to unsigned int, let the compiler knows what we like to do.
sol:
     int g = a1[static_cast<unsigned int>(1)];


Reference:
http://stackoverflow.com/questions/1726740/c-error-operator-2-overloads-have-similar-conversions

Comments

Popular posts from this blog

tex2D vs. tex2Dproj

Fast subsurface scattering

Bringing Large Scale Console Game to iOS