swap2.cc From Astrachan pp 537-538 ---------------------------------- #include #include "clockt.h" #include "CPstring.h" // illustrates use of template functions // Owen Astrachan, 10/11/94 template void Swap(Type & a, Type & b) // generic swap routine { Type temp; temp = a; a = b; b = temp; } int main() { int i1 = 1, i2 = 2; double d1 = 3.1415, d2 = 2.718; ClockTime c1(1,2,3), c2(4,5,6); char ch1 = 'a', ch2 = 'b'; string s1 = "hello", s2 = "world"; Swap(i1, i2); Swap(d1,d2); Swap(c1,c2); Swap(ch1,ch2); Swap(s1,s2); cout << i1 << " " << i2 << endl; cout << d1 << " " << d2 << endl; cout << c1 << " " << c2 << endl; cout << ch1 << " " << ch2 << endl; cout << s1 << " " << s2 << endl; return 0; }