In templates, where and why do I have to put typename
and template
on dependent names?
What exactly are dependent names anyway?
I have the following code:
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> {
};
};
The problem I have is in the typedef Tail::inUnion<U> dummy
line. I’m fairly certain that inUnion
is a dependent name, and VC++ is quite right in choking on it.
I also know that I should be able to add template
somewhere to tell the compiler that inUnion is a template-id. But where exactly? And should it then assume that inUnion is a class template, i.e. inUnion<U>
names a type and not a function?