【发布时间】:2015-01-05 15:47:57
【问题描述】:
我在另一个模板化结构中实现模板化结构时遇到问题。
基本上这是可行的:
template<typename T>
struct ListElement {
T Value;
struct ListElement<T>* Next;
};
template<typename M>
struct List {
struct ListElement<M>* ContainedElements;
};
但我真正想要的是这样的实现:
template<typename T>
struct ListElement {
T Value;
struct ListElement<T>* Next;
};
template<typename M>
typedef struct ListElement<M>* List;
问题是您不能将 typedef 与模板一起使用。写 struct List<Anytype> 代替 struct ListElementPointer* 的任何变通方法?
PS:顺便说一句,这是一个学校项目。不允许使用标准向量或列表类,我不想为我使用的每种类型键入新的定义......也不允许使用类:-/
【问题讨论】:
-
“您不能将 typedef 与模板一起使用”是什么意思。您遇到什么错误或问题?
-
@StephaneRolland 它给出了语法错误,因为它是不允许的。在其他话题中讨论过[link]
标签: c++ templates struct linked-list