Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename T>
- class Vn {
- public:
- ...
- template<typename T> friend void swap(Vn<T>&,Vn<T>&);
- ...
- }
- template<typename T>
- void swap(Vn<T>& a,Vn<T>& b){
- T* tmp=new(std::nothrow) T[a.size];
- T* tmp2=new(std::nothrow) T[b.size];
- size_t tmp3;
- for(size_t i=0;i<a.size;i++)
- {
- tmp[i]=a.v[i];
- }
- for(size_t i=0;i<b.size;i++)
- {
- tmp2[i]=b.v[i];
- }
- delete a.v;
- delete b.v;
- a.v=tmp2;
- b.v=tmp;
- tmp3=a.size;
- a.size=b.size;
- b.size=tmp3;
- }
Add Comment
Please, Sign In to add comment