在模板,在那里,为什么我必须把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>命名一个类型而不是一个函数?
有只小跳蛙
手掌心
随时随地看视频慕课网APP