Singly Linked List, cannot search and add functions don't work

Hey all, I've been assigned by my professor to create a singly linked list of Albums for a hypothetical data structure. I've FINALLY gotten the program to actually run but my search and add functions aren't working. I was hoping I could get some advice on what i'm missing to get this working properly.
Thank you for all your help.

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
#include <iostream>
#include<string>
using namespace std;

class AlbumNode
{
	int year;
	string artist;
	string name;
	string genre;
	string label;
	AlbumNode *next;
	AlbumNode() : next(0) {};
	AlbumNode(int y, string t, string a, string g, string b) : next(0) { year = y; name = a; genre = g; label = b; };
	friend class AlbumList;
	friend void operator<<(ostream& os, const AlbumList& L);
};
class AlbumList {
public:
	AlbumNode *root = NULL;

	bool Search(string n)
	{
		AlbumNode *current = root;
		while (current)
		{
			if (current->name == n) return true;
			else current = current->next;
		}
		return false;
	};
	void Add(int y, string t, string a, string g, string b)
	{
		AlbumNode *temp = new AlbumNode(y, t, a, g, b);
		temp->next = root;
		root = temp;
		return;
	};
	AlbumNode* CopyNode(AlbumNode *n)
	{
		AlbumNode *temp = new AlbumNode();



		if (n->next) temp->next = CopyNode(n->next);
		return temp;


	};
	void Print(ostream& os)
	{
		return DoPrint(os, root);
	};
	void DoPrint(ostream& os, AlbumNode* n) const
	{
		if (n->next)
			DoPrint(os, n->next);
		os << "\t" << n->year << "\t" << n->artist << "\t" << n->name << "\t" << n->genre << "\t" << n->label << "\t" << "\t";
	};
	friend void operator << (ostream& os, const AlbumList& L);
};
void operator << (ostream& os, const AlbumList& L)
{
	os << " [  ";
	AlbumNode *current = L.root;
	//L.Print(os);
	while (current)
	{
		os << current->year << current->artist << current->name << current->genre << current->label << "\t";
		current = current->next;
	}
	os << "]";
};
int main()
{
	AlbumList L;
	L.Add(1968, "\tThe Beatles", "\tThe White Album", "\tApple Records", "\tRock");
	cout << L;
	if (L.Search("\tThe White Album"))
		cout << "Yes Found" << endl;
	else
		cout << "Not Found" << endl;
	// AlbumList L; cout << L;
}

You've made some odd choices and the code doesn't compile as-is.

If I replace line 16 with:
friend void operator<<(ostream& os, const class AlbumList& L); it seems to compile and run with the expected output.

Yes Thank you for that, I'm still learning the ropes, but did make that correction.
Topic archived. No new replies allowed.