以下代码不能使用 gcc 4.7 (20120114) 编译,但可以使用 clang++ 3.0 编译。这是 gcc、clang 中的错误还是仅仅因为我尝试做的事情在 c++11 中是不允许的?
template< typename... args >
struct A {
template< typename head, typename... tags >
struct Inner : public Inner<tags...> {
};
template< typename head >
struct Inner<head> {
// assume both args... and tags... must be used to
// calculate TYPE
typedef int TYPE;
};
};
template< typename... args >
struct B : A<args...> {
template<typename... tags>
typename A<args...>::template Inner<tags...>::TYPE x() {
return 0;
}
};
int main(int argc, const char *argv[]) {
B<int, int, int> b;
b.x<char, short, long, double>();
return 0;
}
上面的代码是我尝试做的一个非常简化的示例,但本质是我需要 args... 类型和 tags... 类型来计算函数的返回类型。如何才能做到这一点?