Reputation: 11
I have a simple linked list of books and I am trying to print the contents of the linked list using this method
void List::display()const{
Node *newNode = head;
while (newNode != NULL){
cout << "ID: " << newNode->book.getId() << " Name: " << newNode->book.getName()<< endl;
newNode = newNode->next;
}
}
My Book
class has the following implementations:
int Book::getId(){
return id;
}
string Book::getName(){
return name;
}
The Book.h
has the following declarations:
class Book{
friend class Node;
friend ostream& operator<<(ostream& output, const Book &book);
public:
Book();
int getId();
string getName();
private:
int id;
string name;
};
Getting it to print the ID
of the book is fine:
cout << "ID: " << newNode->book.getId()
Its the second part which does not work:
cout<<" Name: " << newNode->book.getName()<< endl;
I've tried this before in a couple of different linked lists and it works fine, but I cant figure out what's wrong here,
the error is:
Error 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
Upvotes: 0
Views: 2547