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];
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.
(1)];
Reference:
http://stackoverflow.com/questions/1726740/c-error-operator-2-overloads-have-similar-conversions
class Array
{
Type& operator[] ( unsigned int index );
}
Array
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>Reference:
http://stackoverflow.com/questions/1726740/c-error-operator-2-overloads-have-similar-conversions
Comments
Post a Comment