У меня есть код шаблона, который я бы предпочел хранить в файле CPP, а не в заголовке. Я знаю, что это можно сделать, если вы знаете, какие типы шаблонов будут использоваться. Например:
.h файл
Код: Выделить всё
class foo
{
public:
template
void do(const T& t);
};
Код: Выделить всё
template
void foo::do(const T& t)
{
// Do something with t
}
template void foo::do(const int&);
template void foo::do(const std::string&);
My question is - is this a nasty hack or will this work with other compilers/linkers? I am only using this code with VS2008 at the moment but will be wanting to port to other environments.
Источник: https://stackoverflow.com/questions/115 ... a-cpp-file
Мобильная версия