template <class T>
class List
{
public:
List();
~List();
...
protected:
template <class T> struct Item
{
struct Item* next;
T data;
};
...
struct Item<T>* allocate();
};
template <class T>
struct Item<T>* List<T>::allocate() // error here
{
...
return object; // struct Item<T>*
}
how can i do that?
The problem is deeper in fact:
You don’t have to declare
Itemas beingtemplate, because it’s a nested class within a template class it has access toT.And then you would define
accesslike so:The point here is that
Listis a template class, so its parameters must be specified, while onceTis specified forListit’s not necessary to precise it once again.Note
typename😉