본문 바로가기
프로그래밍/C,C++

C++ Template 샘플

by Planetis 2014. 9. 12.
사용 샘플

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#pragma warning (disable:4996)
 
#include <iostream>
using namespace std;
 
void myswap( int &a, int &b ){
    int temp = a;
    a = b;
    b = temp;
}
 
template <class type>
void myswap( type &a, type &b ){
    type temp = a;
    a = b;
    b = temp;
}
 
void main() {
    int i = 10, j = 20;
    double x = 12.3, y = 34.5;
 
    cout << "i, j\t#\t" << i << ",\t" << j << endl;
    cout << "x, y\t#\t" << x << ",\t" << y << endl;
 
    myswap(i, j);
    myswap(x, y);
     
    cout << "i, j\t#\t" << i << ",\t" << j << endl;
    cout << "x, y\t#\t" << x << ",\t" << y << endl;
}

 


320x100

댓글