8.13 Function templates

주홍영·2022년 3월 13일
0

Learncpp.com

목록 보기
89/199

https://www.learncpp.com/cpp-tutorial/function-templates/

코드의 범용성을 높여주는 function template에 대해서 이야기 한다

In C++, the template system was designed to simplify the process of creating functions (or classes) that are able to work with different data types.
다양한 데이터 타입에서도 쉽게 작동할 수 있는 함수를 간단히 만들도록 도와주는 문법!

사용 예시는 다음과 같다

template <typename T> // this is the template parameter declaration
T max(T x, T y) // this is the function template definition for max<T>
{
    return (x > y) ? x : y;
}
profile
청룡동거주민

0개의 댓글