I am trying to connect all memory leaks (which is massive). I am new to STL. I have a class library where I have 3 sets. I also create a lot of memory with new libraries in the class to add information to collections ...
Do I need to empty kits? If so, how?
Here is the .h library
#pragma once #include <ostream> #include <map> #include <set> #include <string> #include "Item.h" using namespace std; typedef set<Item*> ItemSet; typedef map<string,Item*> ItemMap; typedef map<string,ItemSet*> ItemSetMap; class Library { public: // general functions void addKeywordForItem(const Item* const item, const string& keyword); const ItemSet* itemsForKeyword(const string& keyword) const; void printItem(ostream& out, const Item* const item) const; // book-related functions const Item* addBook(const string& title, const string& author, int const nPages); const ItemSet* booksByAuthor(const string& author) const; const ItemSet* books() const; // music-related functions const Item* addMusicCD(const string& title, const string& band, const int nSongs); void addBandMember(const Item* const musicCD, const string& member); const ItemSet* musicByBand(const string& band) const; const ItemSet* musicByMusician(const string& musician) const; const ItemSet* musicCDs() const; // movie-related functions const Item* addMovieDVD(const string& title, const string& director, const int nScenes); void addCastMember(const Item* const movie, const string& member); const ItemSet* moviesByDirector(const string& director) const; const ItemSet* moviesByActor(const string& actor) const; const ItemSet* movies() const; ~Library(); };
I'm not sure what I need to do for the destructor?
Library::~Library() { }
Also, am I highlighting stringset correctly?
#ifndef CD_H #define CD_H #pragma once #include "item.h" #include <set> typedef set<string> StringSet; class CD : public Item { public: CD(const string& theTitle, const string& theBand, const int snumber); void addBandMember(const string& member); const int getNumber() const; const StringSet* getMusician() const; const string getBand() const; virtual void print(ostream& out) const; string printmusicians(const StringSet* musicians) const; ~CD(); private: string band; StringSet* music; string title; int number; }; ostream& operator<<(ostream& out, const CD* cd); #endif
cd.cpp
#include "CD.h" using namespace std; CD::CD(const string& theTitle, const string& theBand, const int snumber) : Item(theTitle), band(theBand),number(snumber), music(new StringSet) { } CD::~CD() { delete []music; }
in the library class, I create a lot of memory, but does the destructor destroy? Example:
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);
Note. I do not have a copy constructor. I'm not sure if I even need one or how to add it. I don't think my destructors are called either.