Possible Duplicate:
Where and why do I have to put the “template” and “typename” keywords?
I'm trying to use traits for the first time to enable me to succinctly associate related types in some generic routines. However I'm struggling with the syntax and Googling doesn't seem to turn up any simple examples for implementing this kind of thing. Here is condensed example of what I have currently:
template <typename T> struct foo_traits { };
template<> struct foo_traits<int> {
typedef unsigned char T2; // sub-type for int specialisation of foo_traits
};
template <typename T> T foo(void)
{
typedef foo_traits<T> traits_type; // OK
typedef traits_type::T2 T2; // error here: "Too few template-parameter-lists"
T i
T2 j;
// ...
}
What is the correct way to get the T2
typedef from foo_traits
so that I can use it in my generic template function foo
?