[ 완료]책보다 궁금한것이 있어서요...
글쓴이: sinji81 / 작성시간: 화, 2010/02/23 - 11:35오전
template <bool cond, typename A, typename B> struct Select{ typedef A Result; }; template <typename A, typename B> struct Select<false, A, B>{ typedef B Result; };
위처럼 정의를 해놓고...
Select<sizeof(int)==sizeof(long), int, double>::Result temp = 0;
이렇게 구현하면 int와 long의 크기로 인해 temp의 type이 int 또는 long으로 결정된다는 내용인데요..
코드가 이해가 되지 않아서요... temp의 type이 어떻게 결정되는지..ㅠ
가르쳐주세요~~~ㅠ
Forums:
Selectlong >::Result temp =
Select<sizeof(int)==sizeof(long), int, long >::Result temp = 0;
이겠죠?
bool 이 참이면 int, 거짓이면 long 인 객체가 만들어집니다.
일단 일반적인 템플릿 클라스를 정의하고, 거짓인 경우에 specialization 을 해 놓았기 때문에 참인 경우는 일반적인 템플릿 클라스의 객체가 만들어지는 겁니다.
아..답변 감사합니다.
제가 specialization된 template에 대해 이해가 부족한 것 같네요..
감사합니다.
댓글 달기