Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<array>
- #include<algorithm>
- template <class T, class U>
- std::pair<U, T> My_Swap(T a, U b) {
- return std::make_pair(b, a);
- }
- template <class T, size_t N>
- class MyClass {
- T arr[N];
- public:
- MyClass() {
- for (int i = 0; i < N; i++)
- arr[i] = rand() % 10;
- }
- T* get_arr() { return arr; }
- };
- void main() {
- int a = 5;
- double b = 1.2;
- std::cout << "\n Before swap:\n " << a << " " << b << std::endl;
- auto temp = My_Swap(a, b);
- auto new_a = temp.first;
- auto new_b = temp.second;
- std::cout << "\n After swap:\n " << new_a << " " << new_b << std::endl;
- MyClass<int, 4> c, d;
- std::cout << "\n Before swap:\n";
- for (int i = 0; i < 4; i++)
- std::cout << " " << c.get_arr()[i] << " " << d.get_arr()[i] << std::endl;
- auto temp_2 = My_Swap(c, d);
- c = temp_2.first;
- d = temp_2.second;
- std::cout << "\n After swap:\n";
- for (int i = 0; i < 4; i++)
- std::cout << " " << c.get_arr()[i] << " " << d.get_arr()[i] << std::endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement