// swap function using template // #include #include // using namespace std; // conflict with iostream swap thing using std::cout, std::endl; using std::string; template void swap( T &a, T &b) { T c = a; a = b; b = c; } int main() { int i = 1, j = 2; cout << i << " " << j << endl; swap( i, j); cout << i << " " << j << endl; double x = 3.3, y = 4.4; cout << x << " " << y << endl; swap( x, y); cout << x << " " << y << endl; string s = "abc", t = "efg"; cout << s << " " << t << endl; swap( s, t); cout << s << " " << t << endl; }