옵션 2에서 g ++를 사용하여 템플릿 인스턴스화를 컴파일 할 수 있습니다.
// my_class.hpp
template <typename T1, class Container, typename Compare>
class my_class {
// ...
};
및 코드에서 당신은 my_class<long, std::vector<long>, std::greater<long> >
를 사용 : 예를 들어, 한 가정합니다. 당신이 오브젝트 파일로 my_class<long, std::vector<long>, std::greater<long> >
의 인스턴스를 컴파일 할 수 있습니다 ++ g으로 : 어떤 대상이 my_class_long_long_vector_greater_instantiation.o
에 따라
my_class_long_long_vector_greater_instantiation.o: my_class.hpp
경우와 선언 : 하단 근처에 Makefile
에,
// my_class_long_long_vector_greater_instantiation.cpp
#include "my_class.hpp"
template class my_class<long, std::vector<long>, std::greater<long> >;
그런 다음 추가 템플릿 my_class
이 변경되었습니다 (my_class.hpp
파일이 변경됨). 그러면 GNU make가 my_class_long_long_vector_greater_instantiation.cpp
을 다시 컴파일하므로 my_class<long, std::vector<long>, std::greater<long> >
을 다시 인스턴스화합니다.
은 참조 : 닐 버터 워스 코멘트에서 언급 한 바와 같이 Where's the Template?
Make는 클래스를 다루지 않으며 파일을 처리합니다. 다른 헤더 파일처럼 템플릿을 포함하는 파일을 처리합니다. –
필수 파일로 나열 하시겠습니까? – Alex
"필수 파일"이 무슨 뜻인지 몰라 - make는 그런 개념이 없다. 당신은 일반적으로 의존성을 만들 것입니다. –