There are at least two major problems with your code. The most
critical is that you are making operator<<
a member, and
trying to give it three parameters, Which is completely illegal.
If the first parameter is to be an std::ostream&
, there is no
way you can define it as a member; it must be a free function.
If it also needs access to private data, then you'll have to
make it a friend. But be aware:
friend std::ostream& operator<<( std::ostream&, typename List::ListNode const* );
makes a non-template function friend. A different non-template
function for each instantiation of the template. This is rarely
what is wanted. You can make a specific template instantiation
friend, but only if the template function is declared before
hand. Which is impossible in this case, because one of the
arguments of the function has a nested type. The more idiomatic
way of solving this (in my experience, anyway) is to define the
friend inline:
friend std::ostream& operator<<( std::ostream& dest, typename List::ListNode const& p )
{
// ...
}
In this case, operator<<
is also a non-templated function, but
the definition is nested in the class template, so you will get
a new instance of the function automatically.