What will the following program write to standard output when run?
#include <iostream>
namespace one
{
struct thing { };
inline bool operator== (thing const &, thing const &)
{
std::cout << "one::operator==" << std::endl;
return true;
}
}
namespace two
{
typedef one::thing thing;
inline bool operator== (thing const &, thing const &)
{
std::cout << "two::operator==" << std::endl;
return true;
}
}
template <class T>
inline bool operator== (T const &, T const &)
{
std::cout << "::operator==" << std::endl;
return true;
}
int main(int, char * [])
{
{
one::thing foo, bar;
foo == bar;
}
{
two::thing foo, bar;
foo == bar;
}
{
using namespace one;
two::thing foo, bar;
foo == bar;
}
return 0;
}
As an extra question, consider what would be the outcome if the following lines of code where added to main()
?
using namespace two;
one::thing foo, bar;
foo == bar;