为什么必须在何处以及为什么要放置“模板”和“类型名”关键字?
在模板,在那里,为什么我必须把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 ++恰恰可以解决这个问题。
我也知道我应该能够在template
某处添加一些内容来告诉编译器inUnion是一个模板ID。但是到底在哪里?然后应该假设inUnion是一个类模板,即inUnion<U>
命名一个类型而不是一个函数吗?
转载请注明出处:http://www.xinxianzhihui.com/article/20230526/886441.html