File A.hpp:
struct foo
{
int x;
} foo;
inline bool operator ==(const foo &lhs, const foo &rhs)
{
/* ... */
}
File B.hpp
#include "A.hpp"
namespace SomeNamespace
{
bool operator==(const foo &lhs, const foo &rhs)
{
/* ... */
}
/* ... */
void someFunction(const foo &foo_instance1, const foo &foo_instance2)
{
CPPUNIT_ASSERT(foo_instance1 == foo_instance2);
}
}
The compiler error for the line with the ASSERT is:
error: ambiguous overload for 'operator==' ...
So, the problem is that the compiler sees both comparison operators.
The definition in the global namespace of A.hpp and the definition in the SomeNamespace of B.hpp are ambiguous.
Why does the compiler not use the defintion in the SomeNamespace?