템플릿 특수화

Extreme Coding·2022년 1월 20일
0

제 0 순위, 만약 일반 함수가 있다면, 이 함수가 제 0 순위
제 1 순위, 함수 템플릿 중, 특수화가 있다면 특수화가 제 1순위
제 2 순위, 특수화가 없다면, 컴파일러가 1개 이상 대기 코드를 뽑은 뒤에, 이 중 가장 알맞는 코드가 2순위

  • 일정 타입에 대해 특수화를 사용하여 다른 기능을 수행 할 수 있게 할 수 있다.
template<typename T>
struct identity { typedef T type; };
 
template<typename T>
class CConstraint
{
	public:
		template <typename TL>
			void Verify(int position, int* constraints);
 
	private:
		template<typename TL>
			void Verify(int, int*, identity<TL>);
		void Verify(int, int*, identity<int>);
		void Verify(int, int*, identity<long>);
};
template<typename T>
struct ID { typedef T type; };

class CGameObject
{
public:
template<typename T>
	void AddComponent(CComponent* _pCom)
	{
		AddComponent(_pCom, ID<T>());
	}

private:
	template<typename T>
	void AddComponent(CComponent* _pCom, ID<T> _id);
	void AddComponent(CComponent* _pCom, ID<CScript>);
//....
}
profile
나의 개발 일기장!

0개의 댓글