C++ Programming Tips: A Better Swap Function
C++ provides us with a default swap function in the std namespace: namespace std{ template<typename T> void swap(T& a,T& b){ T temp(a); a = b; b = temp; }} As we can see, as long as we write a proper copy constructor and assignment operator for the class, this default swap can effectively swap two … Read more