C++ 可变模板的显式模板实例化

C++ 可变模板的显式模板实例化,c++,templates,c++11,variadic-templates,C++,Templates,C++11,Variadic Templates,我有几个模板类Impl(带有一些抽象方法),它们在CPP文件中部分实现,因此我需要显式实例化我的模板,以便链接器找到它,如下所示: template class Impl<T0>; template class Impl<T1>; template class Impl<T2>; ... template class Impl<Tx>; 在CPP文件中: template class type_map<Impl, MyTypes>;

我有几个模板类
Impl
(带有一些抽象方法),它们在CPP文件中部分实现,因此我需要显式实例化我的模板,以便链接器找到它,如下所示:

template class Impl<T0>;
template class Impl<T1>;
template class Impl<T2>;
...
template class Impl<Tx>;
在CPP文件中:

template class type_map<Impl, MyTypes>;
模板类类型图;
然而,这并没有按照我的意图实例化模板(链接器抱怨缺少符号)


有没有一种方法可以使这种方法起作用(即在不实例化模板对象的情况下实例化模板),或者有一种完全不同的方法可以解决我在这种情况下的问题?

我认为你不能用可变模板来做这件事,但你可以用预处理器来做

我看到两种选择。一种是使用:

使用_file.cpp

X(T0)
X(T1)
X(T2)
X(T3)
X(Tx)

#undef X
#define X(maType) template class Impl<maType>;
#include "x.hpp"

#define X(maType) template class Impl2<maType>;
#include "x.hpp"
#定义X(maType)模板类Impl;
#包括“x.hpp”
#定义X(maType)模板类Impl2;
#包括“x.hpp”

您是否尝试创建dll?也许您必须将导出宏添加到
类型映射中
type@Angew我有几门课都是这样的,这就是我的问题所在。我试图把我的问题表述得更清楚一点。@vlad_tepesch不,我不使用DLL。这只与编译器不生成其他编译单元所需的模板实例有关。一种可能的解决方案是使用宏。尝试使用or。不幸的是,我认为在这种情况下没有其他方法。如果我的类不是抽象的,我只能使用可变模板方法。无论如何谢谢你!
X(T0)
X(T1)
X(T2)
X(T3)
X(Tx)

#undef X
#define X(maType) template class Impl<maType>;
#include "x.hpp"

#define X(maType) template class Impl2<maType>;
#include "x.hpp"