正在调用模板内typedef的构造函数
Calling constructor of typedef inside template
我在一个模板类中定义了typedef:
template <class T>
class ROIAlg{
public:
typedef std::vector<T> Waveform;
typedef typename Waveform::const_iterator Tick;
typedef std::pair<Tick, Tick> Region;
//etc.
};
以及另一个使用它们的类
template <class T>
class WaveformPropertiesAlg{
public:
WaveformPropertiesAlg();
private:
typename ROIAlg<T>::Region fCPR;
//etc.
};
WaveformPropertiesAlg:构造函数的实现
template <class T>
WaveformPropertiesAlg<T>::WaveformPropertiesAlg():
fCPR(ROIAlg<T>::Tick(), ROIAlg<T>::Tick()) {
//etc
}
另一段代码试图构建WaveformPropertiesAlg<short int>
,但编译失败:
In instantiation of ‘WaveformPropertiesAlg<T>::WaveformPropertiesAlg() [with T = short int]’:
RawDigitAndWireComparisonAlg.cxx:13:77: required from here
WaveformPropertiesAlg.h:30:51: error: dependent-name ‘ROIAlg<T>::Tick’ is parsed as a non-type, but instantiation yields a type
fCPR(ROIAlg<T>::Tick(),ROIAlg<T>::Tick())
^
WaveformPropertiesAlg.h:30:51: note: say ‘typename ROIAlg<T>::Tick’ if a type is meant
我不认为这里指的是类型,因为我正在调用Tick的构造函数。我该怎么做?
typedef typename Waveform::const_iterator Tick;
<lt;这是一种类型,因此您需要typename
,因为编译器告诉您:
fCPR(typename ROIAlg<T>::Tick(), typename ROIAlg<T>::Tick())
如果Tick
是其他东西,例如函数:,则不需要typename
template <class T>
class ROIAlg{
public:
static T Tick();
};
相关文章:
- "error: no matching function for call to"构造函数错误
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 为什么在C++中使用私有复制构造函数与删除复制构造函数
- 选择要调用的构造函数
- 如何委托派生类使用其父构造函数?
- 构造函数正在调用一个使用当前类类型的函数
- 没有用于初始化C++中的变量模板的匹配构造函数
- 初始化具有非默认构造函数的std::数组项的更好方法
- 在类中存储 Typedef 构造函数
- 使typedef的构造函数/赋值运算符成为友元函数
- 正在调用模板内typedef的构造函数
- 带有指针和构造函数的 typedef 结构
- Typedef是一个具有特定构造函数参数的类
- 如何使用包含不同typedef枚举的派生类模板设置构造函数初始化列表
- C++标准是否允许使用typedef来重命名构造函数
- 将typedef与构造函数参数一起使用
- 如何使用默认构造函数参数对模板进行typedef
- "using" (typedef) 指针:它的默认构造函数返回 nullptr?