在模板中,我必须将
typename
和
template
依赖的名字?
到底什么是从属名称?
我有以下代码:
template <typename T, typename Tail> // Tail will be a UnionNode too.
struct UnionNode : public Tail {
// ...
template<typename U> struct inUnion {
// Q: where to add typename/template here?
typedef Tail::inUnion<U> dummy;
};
template< > struct inUnion<T> {
};
};
template <typename T> // For the last node Tn.
struct UnionNode<T, void> {
// ...
template<typename U> struct inUnion {
char fail[ -2 + (sizeof(U)%2) ]; // Cannot be instantiated for any U
};
template< > struct inUnion<T> {
};
};
我的问题在于
typedef Tail::inUnion<U> dummy
线路。我很肯定
inUnion
是一个依赖的名称,VC++完全正确地扼杀了它。
我也知道我应该可以补充
模板
告诉编译器inUnion是一个模板id的地方。但是具体在哪里呢?然后它是否应该假设inUnion是一个类模板,即。
inUnion<U>
命名类型而不是函数?