An error on a certain line of code from the memorandum of a tutor

Write your question here.
Is there an error or this line or not?
1
2
3
  Put the code you need help with here.
 friend ostream& operator<< <>(ostream&, const linkedListType<Type>&);
Probably, but without context I won't dare to say.

What does your compiler say? Any error's or warnings?


Does it have to be a friend? What non-public parts of the class does it need?
Are linkedListType and Type are defined?

friend ostream& operator<< <>(ostream&, const linkedListType<Type>&);
What's with the <> ?

Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//Here is the complete header file:
#ifndef LINKEDLISTTYPE_H
#define LINKEDLISTTYPE_H

#include <iostream>
#include <cassert>
using namespace std;

template<class Type>
class linkedListType;

template<class Type>
 ostream& operator<<(ostream, const linkedListType<Type>&);

template <class Type>
struct nodeType
{
	Type info;
	nodeType<Type> *link;
};

template<class Type>
class linkedListType
{
    friend ostream& operator<< <>(ostream&, const linkedListType<Type>&);

	public:
		const linkedListType<Type>& operator=
		                          (const linkedListType<Type>&);
		        //Overload the assignment operator.
		void initializeList();
			   //Initializes the list to an empty state.
			   //Postcondition: first = NULL, last = NULL;
			     //             count = 0;
		bool isEmptyList();
				//Function to determine whether the list is empty.
				//Postcondition: Returns true is the list is empty;
				//               otherwise returns false.
		int length();
			//Function to return the number of nodes in the list.
			//Postcondition: The value of count is returned.
		void destroyList();
			//Function to delete all the nodes from the list
			//Postcondition:  first = NULL, last = NULL,
			//                count = 0;
		Type front();
			//Function to return the first element of the list.
			//Precondition: The list must exist and must not be empty.
			//Postcondition: If the list is empty, then the
			//                progream terminates, otherwise,
			//                the first element of the list is returned
		Type back();
			//Function to return the last element of the list.
			//Precondition: The list must exist and must not be empty
			////Postcondition: If the list is empty, then the
			//                progream terminates, otherwise,
			//                the last element of the list is returned			
	   bool search(const Type& searchItem);
	   		//Function to determine whether searchItem is in the list
			//Postcondition: Returns true of searchItem is found in the list
			//                  otherwise it returns false
		void insertFirst(const Type& newItem);
			//Function to insert newItem in the list
			//PostCondition: first points to the new list and newItem is
			//              is inserted at the beginning of the list
		void insertLast(const Type& newItem);
				//Function to insert newItem at the end of the llist
			//PostCondition: first points to the new list and newItem is
			//              is inserted at the end of the list, and last points
			//              to the last node in the list
		void deleteNode(const Type& deleteItem);
			//Function to delete deleteItem from the list
			//Postcondition: IF found, the node containing deleteItemis deleted
			//               from the list, first point to the first node, and last
			//               points to the last nodeof the updated list.
		void deleteAll(const Type& deleteItem);
			//Delete all occurrences of a given element
		void deleteSmallest();
			//Find and delete the node with the smallest info
		
		linkedListType();
			   //default constructor
			   //Initializes the list to an empty state.
			   //Postcondition: first = NULL, last = NULL,
			   //                count = 0;
		linkedListType(const linkedListType<Type>& otherList);
				//copy constructor
		~linkedListType();
				//destructor
				//Deletes all the nodes from the list.
				//Postcondition: The list object is destroyed
	protected:
		int count;       //variable to store the number of elements
						// in the list
		nodeType<Type> *first;    //pointer to the first node of the list
		nodeType<Type> *last;     ////pointer to the last node of the list
	
	private:
		void copyList(const linkedListType<Type>& otherList);
			//Function to make a copy of otherlist.
			//Postcondition: A copy of otherList is created
			//              and assigned to this list
			};
#endif 
See the section Template friend operators in: http://en.cppreference.com/w/cpp/language/friend
friend ostream& operator<< <>(ostream&, const linkedListType& );
@keskiverto - Thanks.
Here is another example of this friend function.
When I compile this code I get this error:
18 68 C:\Martin\MalikChapter3\LinkedList.h [Warning] friend declaration 'std::ostream& operator<<(std::ostream&, const linkedListType<Type>&)' declares a non-template function [-Wnon-template-friend]
18 68 C:\Martin\MalikChapter3\LinkedList.h [Note] (if this is not what you intended, make sure the function template has already been declared and add <> after the function name here)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

template <class Type>
struct nodeType
{
   Type info;
   nodeType<Type> *link;
};

template<class Type>
class linkedListType
{
   friend ostream& operator<<(ostream&, const linkedListType<Type>&);

public:
    const linkedListType<Type>& operator=
                         (const linkedListType<Type>&); 
    void initializeList(); 
    bool isEmptyList();

   int length();
    void destroyList();
    Type front(); 
    Type back(); 

   bool search(const Type& searchItem);

    void insertFirst(const Type& newItem);

    void insertLast(const Type& newItem);

    void deleteNode(const Type& deleteItem);

    linkedListType(); 

    linkedListType(const linkedListType<Type>& otherList); 

    ~linkedListType();   

protected:
    int count;      //variable to store the number of 
                //elements in the list
    nodeType<Type> *first; //pointer to the first node of 
                           //the list
    nodeType<Type> *last;  //pointer to the last node of 
                           //the list 
private:
    void copyList(const linkedListType<Type>& otherList); 
};
#endif 
Ahh, now we have seen three versions of the friendship:
1
2
3
4
friend ostream& operator<< <>    (ostream&, const linkedListType<Type>&); // your
friend ostream& operator<<       (ostream&, const linkedListType<Type>&); // your
friend ostream& operator<< <>    (ostream&, const linkedListType      &); // cppreference
friend ostream& operator<< <Type>(ostream&, const linkedListType      &); // cppreference 

You did read the explanations at the cppreference.com site, did you?


@AbstractionAnon: I was equally clueless about the <> before websearch reached cppref*
Last edited on
Topic archived. No new replies allowed.