Your swap conflicts with std::swap. Remove using namespace std; above and correct the rest code from std namespace.