Advertisement
rnort

Untitled

Oct 19th, 2011
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. template<class T>
  5.  void swap(T& x,T& y)
  6.  {
  7.    T temp = x;  
  8.    x = y;    
  9.    y = temp;  
  10.  }
  11.  
  12.  
  13. int main(){
  14.  
  15.     float a = 1.12, b = 2.45;
  16.  
  17.     swap(a,b);
  18.     std::cout << "a: " << a << std::endl << "b: " << b << std::endl;
  19.  
  20.     char c = '-', d = '$';
  21.     swap(c,d);
  22.     std::cout << "c: " << c << std::endl << "d: " << d << std::endl;
  23.  
  24.     return 0;
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement