Advertisement
Guest User

codigosh

a guest
Feb 12th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class clase1
  6. {
  7.  public:
  8. int num;
  9. char letra;
  10. clase1(int _num, char _letra): num(_num), letra(_letra){}
  11. };
  12.  
  13.  
  14. void swap(clase1 *objeto1, clase1 *objeto2,clase1 *aux)
  15. {
  16.  
  17.      *aux=*objeto1;
  18.   *objeto1=*objeto2;
  19.   *objeto2=*aux;
  20.  
  21. }
  22. int main()
  23. {
  24.  
  25.    clase1 objeto1(1,'a');
  26.    clase1 objeto2(2,'b');
  27.    clase1 aux(0,' ');
  28.   cout << "objeto1 antes    "<<objeto1.num << " " << objeto1.letra<<endl;
  29.  cout << "objeto2 antes     "<<objeto2.num <<" "<<objeto2.letra<< endl;
  30.  swap(&objeto1, &objeto2, &aux);
  31. cout<<endl;
  32.  cout << "objeto1 despues    "<<objeto1.num<< " " << objeto1.letra<<endl;
  33.   cout << "objeto2 despues    "<<objeto2.num<<" "<<objeto2.letra <<endl;
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement