我对可变参数模板阅读本tutorial,但在下面的代码:C++ typedef和模板语法?
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名称重复:
"::container_type container_type;"
"::type type;"
它不能就这样:
typedef typename container_index<
index-1,
typename C::base_container
> type;
非常感谢。
由于递归?另见[这个问题]中的讨论(http://stackoverflow.com/questions/36913554/c-typedef-and-templates-syntax)。 –