• 코드:
​x
 
1
#include <iostream>
2
using namespace std;
3
​
4
template <typename T>
5
void Swap(T& a, T& b);
6
​
7
template <> void Swap<double>(double&, double&);
8
​
9
int main(void)
10
{
11
    int c = 2, d = 3;
12
    cout << "c : " << c << ", d : " << d << endl;
13
    Swap(c, d);
14
    cout << "c : " << c << ", d : " << d << endl;
15
    
16
    double e = 1.234, f = 4.321;
17
    cout << "e : " << e << ", f : " << f << endl;
18
    Swap(e, f);
19
    cout << "e : " << e << ", f : " << f << endl;
20
    return 0;
21
}
22
​
23
template <typename T>
24
void Swap(T& a, T& b)
25
{
26
    T temp;
27
    temp = a;
28
    a = b;
29
    b = temp;   
30
}
31
​
32
template <> void Swap<double>(double&, double&)
33
{
34
    // double형은 값을 서로 바꾸지 않음. 
35
}
표준입력 & 실행옵션