1.Template
1-1.개념, 사용방법
- template keyword로 generic overloaded function 함수 만들 수 있음.
- generic type T 만들기 → template<class T> // template<typename T>
- template <class T1, class T2, class T3> 도 가능
- Template을 통해 함수에 다양한 type을 적용할 수 있음.
1-2. Specialization
template<typename T>
void Point<T>::Print()
{
std::cout << x << ", " << y << std::endl;
}
template<> //specialization
void Point<int>::Print() {
std::cout << x << ":" << y << std::endl;
}

1-3. Overload and Template
- Template을 사용해서 함수 overloading이 가능함.
- 하지만 type이 명시되어있는 함수가 있으면 그걸 호출함.
template <class T>
void print(T array[], int n){
for(int i=0; i<n; i++){
std::cout << array[i] << '\\t';
}
std::cout << endl;
}
void print(char array[], int n){
for (int i=0; i < n; i++){
std::cout << array[i] << '\\t';
}
std::cout << endl
}
int main(){
int x[] = {1, 2, 3, 4, 5};
print(x, 5); //print(x, 5); -> void print(T array[], int n)를 호출
char c[5] = {'1', '2', '3', '4', '5'};
print(c, 5); // print(c, 5); -> void print(char array[], int n) 를 호출
}
2.STL(Standard Template Library)
- Template으로 만든 Generic class 와 function 라이브러리(이미 만들어져있음)