Прошу помочь правильно экспортировать шаблон из файла реализации. Проект пишу с применением MSVS 2013.
У меня есть два типа, относительно которых пишутся специализации:
struct arch32 {};
struct arch64 {};
И есть конструктор, который расположен в hpp-файле:
namespace PE {
namespace Section {
class Detail
{
public:
template<typename Arch>
Detail(const ImgSectionHeader& header, const Image<Arch>& image);
double entropy() const;
Пытаюсь написать экспорт таким образом:
template Detail::Detail(const ImgSectionHeader& header, const Image<arch32>& image);
template Detail::Detail(const ImgSectionHeader& header, const Image<arch64>& image);
Но получаю ошибку:
implementation.obj : error LNK2019: unresolved external symbol "public: double __thiscall PE::Section::Detail::entropy(void)const " (?entropy@Detail@Section@PE@@QBENXZ) referenced in function "private: void __thiscall readpe::OutputFormatter<struct PE::arch32>::formatSectionsDetails(void)" (?formatSectionsDetails@?$OutputFormatter@Uarch32@PE@@@readpe@@AAEXXZ)
Другими словами, экспорт шаблона написан неверно. Пытаюсь добавить arch32, arch64:
template Detail::Detail<arch32>(const ImgSectionHeader& header, const Image<arch32>& image);
template Detail::Detail<arch64>(const ImgSectionHeader& header, const Image<arch64>& image);
Но теперь другая ошибка, связанная с синтаксисом:
c:\projects\cpp-workspace\readpe\src\pe\implementation\section\section.hpp(114): error C2143: syntax error : missing ';' before '<'
c:\projects\cpp-workspace\readpe\src\pe\implementation\section\section.hpp(114): error C2059: syntax error : '<'
c:\projects\cpp-workspace\readpe\src\pe\implementation\section\section.hpp(115): error C2143: syntax error : missing ';' before '<'
c:\projects\cpp-workspace\readpe\src\pe\implementation\section\section.hpp(115): error C2059: syntax error : '<'
Спасибо @Vlad : Под "Экспорт шаблонов" понимаю сделать доступной реализацию шаблона из одной единицы трансляции в другой другой единице трансляции. Такое возникает когда декларация шаблона в h-файла, а реализация в cpp-файле. Но согласно статье C++11 — removed and deprecated "экспорт шаблонов" в C++11 убрали