Reputation: 147
I'd like to typedef a template type and use this type in a second template class.
First I defined the typedef with a helper struct
template<class T>
struct MyList {
typedef std::map<int, T> Type;
};
and then used it in the second template:
template <class T>
class MySecondClass {
public:
MySecondClass(MyList<T>& list) : list_(list) {}
private:
MyList<T>::Type list_;
};
Unfortunately, the use of MyListT& list;
doesn't work and creates an error.
Upvotes: 2
Views: 224
Reputation: 7602
I think this is what you want:
template <typename T>
class MySecondClass {
public:
MySecondClass(typename MyList<T>::Type& list) : list_(list) {}
private:
typename MyList<T>::Type& list_;
};
Upvotes: 2
Reputation: 93700
MyList<T>::Type
is not the same type as MyList<T>
and you are mixing them in MySecondClass
. Also you may need a typename
prefix on that last declaration.
Upvotes: 1