Guest User

Untitled

a guest
Aug 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. template<typename T>
  2. class Vn {
  3. public:
  4. ...
  5. template<typename T> friend void swap(Vn<T>&,Vn<T>&);
  6. ...
  7. }
  8.  
  9.  
  10.  
  11. template<typename T>
  12. void swap(Vn<T>& a,Vn<T>& b){
  13. T* tmp=new(std::nothrow) T[a.size];
  14. T* tmp2=new(std::nothrow) T[b.size];
  15. size_t tmp3;
  16. for(size_t i=0;i<a.size;i++)
  17. {
  18. tmp[i]=a.v[i];
  19. }
  20. for(size_t i=0;i<b.size;i++)
  21. {
  22. tmp2[i]=b.v[i];
  23. }
  24. delete a.v;
  25. delete b.v;
  26. a.v=tmp2;
  27. b.v=tmp;
  28. tmp3=a.size;
  29. a.size=b.size;
  30. b.size=tmp3;
  31. }
Add Comment
Please, Sign In to add comment