【发布时间】:2015-01-15 10:50:13
【问题描述】:
我需要一个模板类,但问题是,我无法访问嵌套模板的类型:
template<template<class TParamPayload> class TMsg>
class ParameterBasedFilter : public IMsgFilter
{
public:
typedef TMsg<TParamPayload> ExpectedMessage;
typedef TParamPayload::otherType SomeOtherType;
};
这是一个用法(我只想传递一个模板参数,不带逗号)
ParameterBasedFilter<SomeMessage<SomePayload>> filter;
ParameterBasedFilter内部有错误:
error: 'TParamPayload' was not declared in this scope
typedef TMsg<TParamPayload> ExpectedMessage;
^
是否有可能获得嵌套模板类型?我知道,下面的代码可以工作
template<class TParamPayload, template<class> class TMsg>
class ParameterBasedFilter : public IMsgFilter
{
public:
typedef TMsg<TParamPayload> ExpectedMessage;
typedef TParamPayload::otherType SomeOtherType;
};
但是我必须将 2 种类型传递给模板参数:
ParameterBasedFilter<SomePayload, SomeMessage<SomePayload>> filter;
而且看起来很奇怪,因为 SomePayload 被使用了两次。
【问题讨论】:
-
我不认为这是重复的(至少不是提到的问题)。 OP 在问为什么他不能引用模板模板参数的(命名)模板参数,即
TParamPayload(天哪.. 有人知道吗?)。