LinkedList CD/DVD Collection - << Operator Overload

Hello everyone,

I'm having trouble understanding what this error is saying. I'm terrible at understanding operator overloads, and it's worse when the code given isn't really helping me understand the difference between left-hand and right-hand operands. Just the word "operand" gives me a headache since, regrettably, I do not use that term at all when coding.

So here are the errors:
cdclass.cpp(46): error C2679: binary '<<': no operator found which takes a right-hand operand of type 'LinkedList<SongStruct>' (or there is no acceptable conversion)
dvdclass.cpp(47): error C2679: binary '<<': no operator found which takes a right-hand operand of type 'LinkedList<DVDCast>' (or there is no acceptable conversion)


Here are their respective .cpp code:
CDClass.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Operator Overloads
ostream &operator << (ostream &out, const SongStruct &sStruct) {
	out << left << setw(16) << sStruct.songTitle
		<< left << setw(64) << sStruct.songLength;

	return out;
}
ostream &operator << (ostream &out, const CDClass &cdClass) {
	out << left << setw(16) << cdClass.getArtistName()
		<< left << setw(16) << cdClass.getNameTitle()
		<< left << setw(16) << cdClass.getLengthTotal()
		<< left << setw(0) << cdClass.getSongList();

	return out;
}
ostream &operator << (ostream& out, const LinkedList<SongStruct> &sStruct) {
	sStruct.displayList();
	return out;
}

ostream &operator << (ostream& out, const LinkedList<CDClass> &cdClass) {
	cdClass.displayList();
	return out;
}


DVDClass.cpp
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
// Comparative Overloads
ostream &operator << (ostream &out, const DVDCast &dvdStruct) {
	out << left << setw(16) << dvdStruct.actorActress
		<< left << setw(64) << dvdStruct.characters;

	return out;
}

ostream &operator << (ostream &out, const DVDClass &dvdClass) {
	out << left << setw(16) << dvdClass.getNameTitle()
		<< left << setw(16) << dvdClass.getLengthTotal()
		<< left << setw(16) << dvdClass.getReleaseYear()
		<< left << setw(0) << dvdClass.getCastList();

	return out;
}

ostream &operator << (ostream &out, const LinkedList<DVDCast> &dvdStruct) {
	dvdStruct.displayList();
	return out;
}

ostream &operator << (ostream &out, const LinkedList<DVDClass> &dvdClass) {
	dvdClass.displayList();
	return out;
}


The errors are coming from the line that has getSongList() and getCastList(). Since they're both complaining about the right-hand, that should actually mean the const LinkedList<> part of my attempted overloads, right? I've tried looking this up but to no avail.

EDIT: FYI, there are 8 files all trying to work together.
Media.h, Media.cpp (base class)

CDClass.h, CDClass.cpp
DVDClass.h, DVDClass.cpp (both are deriving base class)

LinkedList.h (keeps track of CD/DVD info)

CD_DVD_Collection.cpp (aka main.cpp; adds, removes, updates, deletes, and displays a CD collection or DVD collection)

Last edited on
the word "operand" gives me a headache

Arguments to operators are often called operands.

Since they're both complaining about the right-hand, that should actually mean the const LinkedList<> part of my attempted overloads, right?

Yes, that's right. Edit: Well, the compiler is not complaining about your overload. It is complaining about the code that uses operator << with a LinkedList<> on the right-hand side. For some reason it fails to find an overload of operator<< that can be used this way even though your overload should work as far as I can see.

Perhaps the problem is that you are trying to use the overloads before they have been declared. You probably want to declare them in the header and define them in the source file, like is normally done for regular functions.
Last edited on
Topic archived. No new replies allowed.