You need to qualify the type: List::Item<T>
.
You can use the non-qualified name of the type when you are inside the class declaration, or inside the argument list or body of each of the member functions of the type (or derived classes), but not for the return type. When the compiler resolves the return type, it does not yet know that you are defining a member of the List
template, and as such it will not look inside that class scope.
This is an interesting point of how compilers work that has actually influenced some changes in the upcoming standard to allow auto
like return type definitions:
template<typename T, typename U>
auto sum( T lhs, U rhs ) -> delctype(lhs+rhs)
{ return lhs+rhs; }
The compiler is able to deduce types T
and U
once the arguments are present, but you cannot tell it that the return type is decltype(lhs+rhs)
as return type since neither lhs
nor rhs
are yet in scope. While this is a C++ only problem, it has its roots in the same problem you are facing: the scope of the return type is external to the scope of the method that is being declared.