【发布时间】:2016-08-23 03:38:53
【问题描述】:
我在可变参数模板上阅读了这个tutorial,但在下面的代码中:
template<int index, class C>
struct container_index {
// points to the "next" container type
typedef typename container_index<
index-1,
typename C::base_container
>::container_type container_type;
// points to the next T-type
typedef typename container_index<
index-1,
typename C::base_container
>::type type;
};
这些 typedef 似乎是多余的,但它编译得很好。问题只是我不明白他们为什么会这样,我也没有找到解释这个案例的教程。有人可以给出一些解释吗?为什么重复 typedef 名称:
"::container_type container_type;"
"::type type;"
不可能是这样的:
typedef typename container_index<
index-1,
typename C::base_container
> type;
非常感谢。
【问题讨论】:
-
因为递归?另请参阅this question 中的讨论。
标签: templates c++11 typedef variadic