operator== ambiguous

#include <utility>


typedef std::pair<int, int> pii;

bool operator==(const pii&, const pii&)
{
return true;
}
int main()
{
return 0;
}
// I can conclude that, there is a member function(std::pair<int, int>::operator==) for the class(std::pair<int, int>),
//but the above code goes through the compiling, why not a compiler error about ambiguity?
It's not a member function. It's a function template in the std namespace.
1
2
3
4
5
6
7
8
int main()
{
	pii a{1,2}, b{1,2};
	if (std::operator==(a, b))
	{
		std::cout << "Yay!" << std::endl;
	}
}

Normal functions are preferred before function templates so that's why you can use your operator== without any ambiguous errors.
Many Thanks!

I think you are right!
Topic archived. No new replies allowed.