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

잔글 (Jmnote 사용자가 제네릭 문서를 제네릭 프로그래밍 문서로 옮겼습니다)
 
(사용자 2명의 중간 판 7개는 보이지 않습니다)
1번째 줄: 1번째 줄:
{{다른뜻|제네릭(generic)|제네릭}}
{{다른뜻|제네릭 (프로그래밍)}}
==개요==
==개요==
;generic programming; generic
;generic programming, generic
;제네릭 프로그래밍; 제네릭
;제네릭 프로그래밍, [[제네릭]]
* 데이터 형식에 의존하지 않고 하나의 값이 여러 다른 데이터 타입들을 가질 수 있는 방식
* 데이터 형식에 의존하지 않고 하나의 값이 여러 다른 데이터 타입들을 가질 수 있는 방식
* 다양한 자료형을 각각 따라 쓰는 대신 하나로 통칭할 수 있음
* 다양한 자료형을 각각 따라 쓰는 대신 하나로 통칭할 수 있음


==예시==
==예시==
<source lang="cpp">
<syntaxhighlight lang="cpp">
template<typename T>  
template<typename T>  
class List  
class List  
15번째 줄: 17번째 줄:
List<Animal> list_of_animals;
List<Animal> list_of_animals;
List<Car> list_of_cars;
List<Car> list_of_cars;
</source>
</syntaxhighlight>
<source lang="cpp">
<syntaxhighlight lang="cpp">
template<typename T>
template<typename T>
void Swap(T & a, T & b) //"&" passes parameters by reference
void Swap(T & a, T & b) //"&" passes parameters by reference
28번째 줄: 30번째 줄:
Swap( world, hello );
Swap( world, hello );
cout << hello << world << endl; //Output is "Hello, world!"
cout << hello << world << endl; //Output is "Hello, world!"
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==
34번째 줄: 36번째 줄:
*[[덕 타이핑]]
*[[덕 타이핑]]
*[[swap]]
*[[swap]]
*[[인덱서]]


==참고 자료==
==참고==
*https://en.wikipedia.org/wiki/Generic_programming
*https://en.wikipedia.org/wiki/Generic_programming


[[분류: 프로그래밍]]
[[분류: 제네릭]]

2021년 10월 31일 (일) 20:33 기준 최신판

  다른 뜻에 대해서는 제네릭(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 }}