Zunächst einmal Entschuldigung, wenn ich dumme Fragen stelle, aber ich bin ein Anfänger in C++.NUR ein Element in einer Multimap finden mit seinem Wert C++
Ich schreibe ein System, das eine Bibliothek darstellt, und es gibt eine Memberfunktion meiner Bibliotheksklasse, die es uns ermöglichen soll, ein Buch zu entfernen. Wenn das Buch nun von einem Benutzer ausgeliehen wird, bedeutet dies, dass sich ein Element in meinem _usersLoaningMultimap
(multimap<UserId,LoanInfo>
) befindet. Wie kann ich die gewünschte LoanInfo finden, ohne den Schlüssel zu kennen (UserId)?
bool Library::removeBook(const BookId& bookId){
//how to find my book in my library without knowing who loaned it.
}
Nur um es klarer, meine Klassenbibliothek ist wie folgt aus:
class Library {
public:
Library();
void addUser(const UserId&, const string&);
Optional<string>& getUserInfo(const UserId& userId);
void addBook(const BookId& bookId, const string& description);
Optional<string>& getBookInfo(const BookId& bookId);
bool returnBook(const UserId& userId, const BookId& bookId);
void loanBook(const UserId& userId,LoanInfo& loan);
bool removeUser(const UserId& userId);
void getLoansSortedByDate(const UserId,std::vector<LoanInfo>& loanVector);
~Library() {}
private:
map<BookId, string> _bookMap;
map<UserId, string> _userMap;
multimap<UserId, LoanInfo> _usersLoaningMultimap;
};
vielen Dank! – adlsc