Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <iostream>
- using namespace std;
- void _swap(int & , int & );
- void _swap(float &f1, float &f2);
- template <typename T> void _swap (T &, T &);
- template <typename T> void monitor (T &, T &);
- ///////////////////////////////////////////////////////
- int main() //
- {
- int n1 = 1,
- n2 = 2;
- float f1 = 1.32,
- f2 = 2.94;
- char c1 = 'Y',
- c2 = 'Q';
- _swap(n1, n2);
- // printf("Address of n1 = %d\n", &n1);
- printf("n1 = %d\n", n1);
- printf("n2 = %d\n", n2); _swap(f1, f2);
- printf("f1 = %f\n", f1);
- printf("f2 = %f\n", f2); _swap(c1, c2);
- printf("c1 = %c\n", c1);
- printf("c2 = %c\n", c2);
- monitor(c1, c2);
- }
- template <typename T>
- ///////////////////////////////////////////////////////
- void monitor(T &n1, T &n2)
- {
- cout << "param 1 = " << n1 << endl;
- cout << "param 2 = " << n2 << endl;
- }
- template <typename T>
- ///////////////////////////////////////////////////////
- void _swap(T &n1, T &n2)
- {
- printf("Template foo is worked\n");
- T n = 0;
- n = n1;
- n1 = n2;
- n2 = n;
- }
- ///////////////////////////////////////////////////////
- void _swap(int &n1, int &n2)
- {
- // printf("Address of n1 (swap) = %d\n", &n1);
- int n = 0;
- n = n1;
- n1 = n2;
- n2 = n;
- }
- ///////////////////////////////////////////////////////
- void _swap(float &f1, float &f2)
- {
- float f = 0;
- f = f1;
- f1 = f2;
- f2 = f;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement