Guest User

Untitled

a guest
Aug 17th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. template<class U>
  5. class square
  6. {
  7. U x;
  8. U y[5];
  9. public:
  10. square()
  11. {
  12. cout<<"Enter xn";
  13. cin>>x;
  14. cout<<"Enter array valuesn";
  15. for(int i=0;i<5;i++)
  16. {
  17. cin>>y[i];
  18. }
  19. }
  20. void display()
  21. {
  22. cout<<endl<<"x="<<x<<endl;
  23. cout<<"array valuesn";
  24. for(int i=0;i<5;i++)
  25. {
  26. cout<<" "<<y[i];
  27. }
  28. }
  29.  
  30. };
  31.  
  32. template<class T>
  33. void swap(T &a,T &b)
  34. {
  35.  
  36. T temp;
  37. temp=a;
  38. a=b;
  39. b=temp;
  40.  
  41. }
  42.  
  43. main()
  44. {
  45. square<int>A;
  46. square<int>B;
  47.  
  48. cout<<"nBefore swapn";
  49. A.display();
  50. B.display();
  51. swap<square>(A,B); // This shows error....why ?
  52. cout<<"nAfter swapn";
  53. A.display();
  54. B.display();
  55. }
Add Comment
Please, Sign In to add comment