I am trying to find an author in a set, and i am having problems doing so.
in the library.cpp is where i am adding the information from main()
#include "Library.h"
#include "book.h"
#include "cd.h"
#include "dvd.h"
#include <iostream>
// general functions
ItemSet allBooks;
ItemSet allCDS;
ItemSet allDVDs;
ItemSetMap allBooksByAuthor;
ItemSetMap allmoviesByDirector;
ItemSetMap allmoviesByActor;
ItemSetMap allMusicByBand;
ItemSetMap allMusicByMusician;
const Item* Library::addBook(const string& title, const string& author, const int nPages)
{
ItemSet* obj = new ItemSet();
Book* item = new Book(title,author,nPages);
allBooks.insert(item); // add to set of all books
obj->insert(item);
allBooksByAuthor[author] = obj;
return item;
}
const ItemSet* Library::booksByAuthor(const string& author) const
{
return allBooksByAuthor[author];
}
I want to be able to return all the books by a particular author. Right now i am adding them by
allBooksByAuthor[author] = obj;
it does work. However,
it is a problem since its treating an author of two different books as a duplicate. so, it will only return one book.
What can i do.. keep in mind i cannot change the function or the sets. so, any const must stay... but can make a new set.