Advertisement
mario_mos

template mario

Aug 31st, 2023 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <iostream>
  2. #include "test.h"
  3. using namespace std;
  4.  
  5. template<typename T>
  6. void swap_t( T& arg1 , T& arg2)
  7. {
  8.    T tmp;
  9.    tmp = arg1;
  10.    arg1 = arg2;
  11.    arg2 = tmp;
  12. }
  13. int main()
  14. {
  15.     int i=3;int j=2;    
  16.  
  17.     swap_t(i,j);
  18.     cout << i << " " << j << endl;
  19.     test obj1, obj2;
  20.     obj1.m_1 = 10;
  21.     obj2.m_1 = 20;
  22.     swap_t(obj1.m_1 ,obj2.m_1);
  23.     cout << obj1.m_1 << " " << obj2.m_1 << endl;
  24.  
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement