I have written a nice comparison template for c-style arrays as seen below. The only problem is: the operator== is not applied (not found?) by the compiler in the following simple code:
int Array1[3];
int Array2[3];
bool is_equal = ( Array1 == Array2 );
Here is my template
template<typename T, size_t N>
bool operator==( const T ( &A )[N], const T ( &B )[N] )
{
for ( int i = 0; i < N; ++i )
{
if ( A[i] != B[i] )
{
return false;
}
}
return true;
}
If I rename the operator==(...)
to Equals(...)
everything works fine.
Why is this???
I also am unsure about the placement of const in the function. Obviously, I want to use 'const &' as for any good comparison operator.