"제네릭 (프로그래밍)"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-<source +<syntaxhighlight , -</source> +</syntaxhighlight>))
잔글 (Jmnote님이 제네릭 프로그래밍 문서를 제네릭 (프로그래밍) 문서로 이동했습니다)
(차이 없음)

2021년 10월 31일 (일) 20:33 판

1 개요

generic programming, generic
제네릭 프로그래밍, 제네릭
  • 데이터 형식에 의존하지 않고 하나의 값이 여러 다른 데이터 타입들을 가질 수 있는 방식
  • 다양한 자료형을 각각 따라 쓰는 대신 하나로 통칭할 수 있음

2 예시

template<typename T> 
class List 
{ 
   /* class contents */ 
};

List<Animal> list_of_animals;
List<Car> list_of_cars;
template<typename T>
void Swap(T & a, T & b) //"&" passes parameters by reference
{
   T temp = b;
   b = a;
   a = temp;
}

string hello = "world!", world = "Hello, ";
Swap( world, hello );
cout << hello << world << endl; //Output is "Hello, world!"

3 같이 보기

4 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}