생성일: 2022년 12월 14일 오전 12:35
최종 편집 일시: 2022년 12월 15일 오후 5:13
cpp notion
templates
템플릿 !
ex00 Start with a few functions
함수 템플릿 만들고 다뤄보기
namespace NamespaceA{
int x;
}
int x;
int main() {
int x;
// the x in main()
x = 0;
// The x in the global namespace
::x = 1;
// The x in the A namespace
NamespaceA::x = 2;
}
ex01 Iter
함수 템프릿 Iter 만들기
template <typename T>
void iter(T *arr, size_t len, void (*func)(T &)){
for (size_t i = 0; i < len; i++)
func(arr[i]);
}
template <typename T>
void iter(T const *arr, size_t const len, void (*func)(T const &)){
for (size_t i = 0; i < len; i++)
func(arr[i]);
}
ex02
클래스 템플릿 Array 만들기