Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- template<class U>
- class square
- {
- U x;
- U y[5];
- public:
- square()
- {
- cout<<"Enter xn";
- cin>>x;
- cout<<"Enter array valuesn";
- for(int i=0;i<5;i++)
- {
- cin>>y[i];
- }
- }
- void display()
- {
- cout<<endl<<"x="<<x<<endl;
- cout<<"array valuesn";
- for(int i=0;i<5;i++)
- {
- cout<<" "<<y[i];
- }
- }
- };
- template<class T>
- void swap(T &a,T &b)
- {
- T temp;
- temp=a;
- a=b;
- b=temp;
- }
- main()
- {
- square<int>A;
- square<int>B;
- cout<<"nBefore swapn";
- A.display();
- B.display();
- swap<square>(A,B); // This shows error....why ?
- cout<<"nAfter swapn";
- A.display();
- B.display();
- }
Add Comment
Please, Sign In to add comment