This is an attempt to rewrite some of the old homework using STL algorithms instead of hand loops and much more.
I have a class called Database that contains Vector<Media *>where Media * can be (among other things) a CD or book. The database is the only class that processes dynamic memory, and when the program starts, it reads a file formatted as shown below (somewhat simplified), allocating space when it reads records, adding them to the vector (v_) above.
CD
Artist
Album
Idnumber
Book
Author
Title
Idnumber
Book
...
...
, , : EDIT: , , " " . , - , find_if , . /EDIT.
typedef vector<Media *>::iterator v_iter;
...
void Database::removeById(int id) {
v_iter it = find_if(v_.begin(), v_.end(), Comparer(id));
if (it != v_.end()) {
delete *it;
v_.erase(it);
}
}
- true, , , . , valgrind , STL, -, -
void Database::removeById(int id) {
v_.erase(remove_if(v_.begin(), v_.end(), Comparer(id)), v_.end());
};
, , "", valgrind, ? , - - 3 allocs 'not freed' Media, .