swap.cpp (253B)
1 #include <iostream> 2 3 template<typename S, typename T> 4 void swap(S& a, T& b) { 5 S tmp = a; 6 a = b; 7 b = tmp; 8 } 9 10 int main() { 11 int x = 3; 12 std::string y = "1.0"; 13 swap(x, y); 14 std::cout << "x: " << x << std::endl; 15 std::cout << "y: " << y << std::endl; 16 }