【发布时间】:2019-05-14 10:38:17
【问题描述】:
我正在尝试使用模板模板参数作为其他模板参数的默认值,但是当我尝试使用标识符(模板模板参数名称/id)时,找不到它。 我正在使用 VS 2013。 这个想法是我有一个基于特定类型的模板实例化的“工厂”类我需要返回另一个具有相同数量的参数 (4) 但具有相同专业化的对象。
template<class T1, class T2,class T3, class T4>
class CommandBus
{...}
template <
template<class T1, class T2, class T3, class T4> class ListenerType,
//The Line bellow fails to compile, T1 is not visible
//E0020 identifier "T1" is undefine
class CommandBusType = CommandBus<T1, T2, T3, T4> >
class CommandBusFactory {
static auto Get() {
return CommandBusType{};
}
};
int main{
//Say I would Have some Object :
Listener<int, int ,int int> Listener;
//Withought the Factory I would have to manually generate a ComamndBus of the same specialization (int , int , int, int):
CommandBus<int,int,int,int> cmdBus;
//But I could use a factory, things should look like:
Listener<int, int ,int int> listener;
auto cmdBus = CommandBusFactory<Listener<int,int,int,int>>::Get();
}
我原以为这会起作用,但编译器抱怨说,例如 未找到模板参数 CommandBusType 的默认值 (CommandBus) 的标识符 T1、T2 等。
是否可以使用模板模板参数作为其他模板参数的默认值?
【问题讨论】:
-
粗体字的简短回答似乎是否定的:stackoverflow.com/questions/28992265/…