SlideShare a Scribd company logo
1 of 6
Download to read offline
C++ !
http://blog.naver.com/ruvendix
템플릿의 필요성
여러 자료형에 적용할 수 있는 클래스를 만들고 싶은데…
그렇게만 된다면 관리를 목적으로 하는 클래스도 만들 수 있는데…
좋아! 여러 자료형에 적용할 수 있는 문법을 만들자!
http://blog.naver.com/ruvendix
템플릿의 모습(함수 템플릿과 템플릿 함수)
template <typename T>
T Add(T tData1, T tData2)
{
return (tData1 + tData2);
}
Add<int>(10, 20);
Add(10.26, 20.15);
템플릿 사용 방법
함수 템플릿
명시적 인자
이 둘은 템플릿 함수
묵시적 인자
http://blog.naver.com/ruvendix
템플릿의 특수화
template <typename T>
T Add(T tData1, T tData2)
{
return (tData1 + tData2);
}
template <> int Add<int>(int iData1, int iData2)
<> 안을 비우고, 특수화할 자료형을 명시!
http://blog.naver.com/ruvendix
클래스 템플릿과 템플릿 클래스
template <typename T>
class CData
{
T Data;
}
// 클래스 템플릿의 특수화
template <> class CData<char>
{
char cNum;
}
// 템플릿 클래스
CData<int>(); // 반드시 템플릿 인자를 명시!
클래스 템플릿
http://blog.naver.com/ruvendix

More Related Content

Viewers also liked

클래스의 추가 지식
클래스의 추가 지식클래스의 추가 지식
클래스의 추가 지식. Ruvendix
 
Google coding guide
Google coding guideGoogle coding guide
Google coding guide. Ruvendix
 
여러 생성자
여러 생성자여러 생성자
여러 생성자. Ruvendix
 
Hello c++ world
Hello c++ worldHello c++ world
Hello c++ world. Ruvendix
 
자료형과 값
자료형과 값자료형과 값
자료형과 값. Ruvendix
 
Begin with Data Scientist
Begin with Data ScientistBegin with Data Scientist
Begin with Data ScientistNarong Intiruk
 
표준 입출력
표준 입출력표준 입출력
표준 입출력. Ruvendix
 
El rescate del PMUS de Madrid: del papel a la acción
El rescate del PMUS de Madrid: del papel a la acción El rescate del PMUS de Madrid: del papel a la acción
El rescate del PMUS de Madrid: del papel a la acción Ecologistas en Accion
 
Meteor 0.3.6 Preview
Meteor 0.3.6 PreviewMeteor 0.3.6 Preview
Meteor 0.3.6 PreviewJuntai Park
 
엘라스틱서치 분석 이해하기 20160623
엘라스틱서치 분석 이해하기 20160623엘라스틱서치 분석 이해하기 20160623
엘라스틱서치 분석 이해하기 20160623Yong Joon Moon
 
2016 software engineering workshop 알려주지 않았지만 알아야 하는 사실들
2016 software engineering workshop 알려주지 않았지만 알아야 하는 사실들2016 software engineering workshop 알려주지 않았지만 알아야 하는 사실들
2016 software engineering workshop 알려주지 않았지만 알아야 하는 사실들Junsu Kim
 
Important Questions of fourier series with theoretical study Engg. Mathem...
Important Questions  of  fourier series with theoretical study   Engg. Mathem...Important Questions  of  fourier series with theoretical study   Engg. Mathem...
Important Questions of fourier series with theoretical study Engg. Mathem...Mohammad Imran
 

Viewers also liked (19)

전처리기
전처리기전처리기
전처리기
 
클래스의 추가 지식
클래스의 추가 지식클래스의 추가 지식
클래스의 추가 지식
 
Google coding guide
Google coding guideGoogle coding guide
Google coding guide
 
여러 생성자
여러 생성자여러 생성자
여러 생성자
 
Hello c++ world
Hello c++ worldHello c++ world
Hello c++ world
 
동적할당
동적할당동적할당
동적할당
 
배열
배열배열
배열
 
구조체
구조체구조체
구조체
 
자료형과 값
자료형과 값자료형과 값
자료형과 값
 
포인터
포인터포인터
포인터
 
Begin with Data Scientist
Begin with Data ScientistBegin with Data Scientist
Begin with Data Scientist
 
Borang kss 1
Borang kss 1Borang kss 1
Borang kss 1
 
표준 입출력
표준 입출력표준 입출력
표준 입출력
 
El rescate del PMUS de Madrid: del papel a la acción
El rescate del PMUS de Madrid: del papel a la acción El rescate del PMUS de Madrid: del papel a la acción
El rescate del PMUS de Madrid: del papel a la acción
 
Meteor 0.3.6 Preview
Meteor 0.3.6 PreviewMeteor 0.3.6 Preview
Meteor 0.3.6 Preview
 
엘라스틱서치 분석 이해하기 20160623
엘라스틱서치 분석 이해하기 20160623엘라스틱서치 분석 이해하기 20160623
엘라스틱서치 분석 이해하기 20160623
 
2016 software engineering workshop 알려주지 않았지만 알아야 하는 사실들
2016 software engineering workshop 알려주지 않았지만 알아야 하는 사실들2016 software engineering workshop 알려주지 않았지만 알아야 하는 사실들
2016 software engineering workshop 알려주지 않았지만 알아야 하는 사실들
 
2do Campeonato Universitario 2016 UPR Cayey
2do Campeonato Universitario  2016 UPR Cayey2do Campeonato Universitario  2016 UPR Cayey
2do Campeonato Universitario 2016 UPR Cayey
 
Important Questions of fourier series with theoretical study Engg. Mathem...
Important Questions  of  fourier series with theoretical study   Engg. Mathem...Important Questions  of  fourier series with theoretical study   Engg. Mathem...
Important Questions of fourier series with theoretical study Engg. Mathem...
 

템플릿