제네릭 (프로그래밍)

  다른 뜻에 대해서는 제네릭(generic) 문서를 참조하십시오.
  다른 뜻에 대해서는 제네릭 (프로그래밍) 문서를 참조하십시오.

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 }}