Last updated
Attention Microsoft Visual C++ Users:At the time The C++ Standard Library From Scratch was written, Visual C++ version 6.0 was the the most current compiler from Microsoft. The book and examples have numerous work-arounds for compiler and library bugs in VC++ 6.0 that are no longer necessary in the newer VC++ 7.0 (aka VC++.NET). Please not the following important points: Visual C++ 6.0 users: Although it is mentioned in the introduction, it is worth repeating here that the library that shipped with VC++ 6.0 had some significant bugs. To get the latest bug fixes, you must do two things:
Visual C++ 7.0 (.NET) users: throughout the example code there are conditionals of the form #ifdef _MSC_VER that should no longer be used for the newer compiler. The best solution is to change each of these conditionals to #if defined(_MSC_VER) && _MSC_VER < 1300. Beginning with Chapter 8, this change is crucial to prevent infinite recursion and stack overflow. Thanks to Stephen Goodman for doing the detective work on this. |
127: while (iter != endIter)
Should be replaced with:
127: while (*iter < *endIter) // empty loop if *endIter absent
This change prevents a potential endless loop if the user edits a record such that it is no longer in the search results. This change will not prevent the item from showing up in the list, but it will prevent the endless loop.
while (! myset.empty()) { myclass* p = *myset.begin(); myset.erase(myset.begin()); delete p; }If the container type is not known or is known to be vector, then the following is more efficient:
template <class Container> void deleteAndClear(Container& mycontainer) { // This code works for all standard containers except map and multimap while (! mycontainer.empty()) { Container::iterator i = mycontainer.end(); Container::value_type p = *--i; mycontainer.erase(i); delete p; } }The function template above works only for containers with bi-directional or random-access iteratators (including all of the standard sequence containers and the set container). Neither of the above code fragments work unchanged for map or multimap containers, although the same basic techniques can be used for maps or multimaps container pointer keys and/or pointer values.