Here I am writing a piece of code to see which one swapwill be called, but the result will not. Nothing is output.
#include<iostream>
class Test {};
void swap(const Test&lhs,const Test&rhs)
{
std::cout << "1";
}
namespace std
{
template<>
void swap(const Test&lhs, const Test&rhs)
{
std::cout << "2";
}
}
using namespace std;
int main()
{
Test a, b;
swap(a, b);
return 0;
}
Which one swapis being called? And in another case, why is it called specialized swapwithout a constspecifier, and not ::swap?
source
share