tags:

views:

152

answers:

1

I'm trying to do something like this (completely synthetic example, because the real code is a bit to convoluted):

enum MyInfoType
{
    Value1, Value2
};

template<typename T> struct My_Type_Traits
{};

template<> struct My_Type_Traits<int>
{
    typedef MyInfoType InfoType;
};

template<typename T>
class Wrap
{
     template<My_Type_Traits<T>::InfoType INFO> int GetInfo()
     {...}
};

...
Wrap<int> w;
int info = w.GetInfo<Value1>();

So basically I'm trying to use a typedef from inside another struct as type of a template parameter. With this code however the compiler complains that struct My_Type_Traits<T>::InfoType is not a type. So what do I need to do to make this work?

+8  A: 

You need to use the typename keyword: like typename My_Type_Traits<T>::InfoType to let the compiler know you're referring to a nested type.

Charles Salvia