These error messages really belong together:
a.cc:41: error: declaration of 'class L' a.cc:26: error: shadows template parm 'class L'
This means that on line 41 you enter the pattern parameter L; in my copy it refers to
template <class L> friend ostream & operator<<(ostream& os, const LinkedList<L> listToprint);//error two
And this declaration obscures the template parameter on line 26:
template <class L>//error one class LinkedList
You need to rename the template parameter in the friend declaration.
Change Relevant language specification - 14.6.1 / 7
The template parameter should not be updated within its competence (including nested areas). The template parameter must not have the same name as the template name.
When you reference L in const LinkedList<L> listToprint , it is unclear whether you have a L value of a friend or an L class. Therefore write
template <class L1> friend ostream & operator<<(ostream& os, const LinkedList<L1> listToprint);
Martin v. LΓΆwis
source share