작성
·
350
0
template에서 template <typename T, typename Container = std::vector<T>, typename Predicate = std::less<T>> 이렇게 정의 해주시고 클레스 내부에서
Container _heap = {};
Predicate _predicate = {};
이런식으로 빈객체를 만들어 주셨다고 하셨는데 저는
template에서 typename Predicate는 std::less<T>를 Predicate로 그냥 정의한 것이고,
내가 새롭게 정의한 자료형? 이기때문에
Predicate(자료형) predicate = {} (중괄호 초기화로 기본생성자 호출하여); => Predicate라는 자료형을 가지는 변수이름이 _predicate인 객체를 만들었다는 뜻인가요??
답변 1
0
typename Predicate에서 Predicate은 새로 정의한 자료형은 아니고
template 특성상 조커 카드처럼 우리가 아무거나 넣어줄 수 있는 것입니다.
typename Predicate = less<T>의 의미는, 아무것도 설정하지 않으면
less<T>로 간주하겠다는 의미이지 Predicate이라는 새로운 자료형을 정의하는게 아닙니다.
하지만 그 다음 Predicate _predicate;으로 해당 타입의 멤버 변수를 이용해
Predicate 타입의 _predicate 객체를 만든 것은 맞습니댜ㅏ.