The reason of the error is your directive using namespace std; You placed names from this name space and among them the name swap into global namespace. When you call swap without qualificztion the compiler does not know which function to call either your function or std::swap You can explicitly specify that you are going to use your function ::swap( a, b );