9.2.            _______________________________249

9.2.1.    

         .
     ,    .

  swap.cpp

// 

template <class T>
void swap(T& x, T& )
(

 temp;

t emp = x ;

x = ;

 = t emp ;

}

 ,     ,
       .

int i , j ;

char strl[100], str2[200], ch;

complex cl, c2;

swap (i, j) ;                 //, i  j  
swaptcl, c2);               //, cl, c2  
swap(strl[50], str2[33]);   //,   

// char
swap(i, ch2);               //i int, ch char  
swap(strl, str2);           //:  

// 

 swap ()    ,    
,       :

void swap(char* si, char* s2)
{

int max_len;

max_len = (strlen(sl) >= strlen(s2)) ?
strlen(sl) : strlen(s2);

char* temp = new char[max_len + 1];

strcpy(temp, si);

strcpy(si, s2) ;

strcpy(s2, temp);

delete []temp;

      ,    -
    swap ()     
   .