I have a class which needs two separate templates passed into it:
template <typename T> class AwesomeClass { TList *theList; typename list <T>::iterator theiterator; public: template <typename TList> AwesomeClass(TList &list) { theList = &list; }; } As you can probably tell it essentially provides a wrapper for the STL (I have to do it this way). Ideally I do not want to pass both templates through at object declaration like this:
typedef AwesomeClass<int, BaseClass<int> > BaseClassIteratorInt; and would rather get away with this:
typedef BaseClass<int> ListFromBaseClassInt; typedef AwesomeClass<int> BaseClassIteratorInt; BaseClassIteratorInt newInt(ListFromBaseClassInt) (This is what the above code is meant to do)
However, I keep getting the error:
error C2143: syntax error : missing ';' before '*'
For the variable TList* theList.
I would need the to ctor to provide the type for TList, is there a way to do this?
Extra steps:
Okay, I now have code of the format:
template <typename Container> class AwesomeClass { public: typedef typename std::common_type< Container > value_type; bool firstUse; Container *theList; typename Container::iterator theIterator; explicit AwesomeClass(Container &list):theList(&list) { }; } This is using common_type to get around a compiler bug which stop the line
typedef typename Container::value_type value_type; compiling due to value_type not being a part of the global namespace.
But I have a compiler error for theIterator, the compiler claims that it needs a ';' before it.
Can anyone see what is wrong?
std::list<T>? You might want to explain your purpose better, as this doesn't make much sense at first sight.typedef typename std::common_type<Container>::type::value_type value_type;. Otherwisevalue_typewill be e.g.std::common_type<std::list<int>>instead ofint.