C++ Template Swap Function
Hello, I need to make a swap function that swaps two parameters of type T.
And following is what I code but something must be wrong.
Could anybody better my codes?
1 2 3 4 5 6
|
template<typename T>
void swap (T& a, T& b)
{ T temp = a;
a = b;
b = temp;
}
|
Should I pass it as constant reference? But I am changing the values right?
Please let me know thanks!!
better code:
#include <utility>
(That's where that function is declared in C++)
As for your replacement, what exactly is " wrong"?
Topic archived. No new replies allowed.