Errata for The C++ Programming Language

Errata for Bjarne Stroustrup: The C++ Programming Language (2nd edition), Addison-Wesley, 1991. ISBN0-201-53992-6.

This is errata for the 9th printing. All but the last few corrections at the end of the list are fixed for the current printing.

You find the printing number as the first number on the last line of the copyright page.

I only list things that can affect understanding. Spelling mistakes you can fix yourself if you spot them.

I very much appreciate reports of errors and constructive comments on the contents in general.

For brevity, I use the old replacement syntax: s/old/new/

- Bjarne


pg54: s/char* q = p;/const char* q = p;/

pg55: s/sec7.10/sec7.11/

pg80: s/look(const char*)/look(const char*, int =0)/

pg113: s/#define "myheade.h"/#include "myheade.h"/

pp154-155: look() and insert() takes const char* arguments.

pg156: s/delete n->string;/delete[] n->string;/

s/delete tbl;/delete[] tbl;/

s/char* pp = p;/const char* pp = p;/

pg158: s/ok(int&/ok(const int&/

pg194: s/#include//

s/#include/#include/

pg227: fourth line from bottom: s/increment/decrement/

pg230: += and *= should return complex&

pg254: s/sec5.3/sec7.14.3/

pg265: top line: add template

pg279: The 2nd sentence of sec8.6 should read: ``In addition to type arguments, variable names, function names, and constant expressions can be used.

pg286: the definition of Map should read:

	template class Map {
	    friend class Mapiter;
	    Link* head;
	    Link* current;
	    V def_val;
	    K def_key;
	    int sz;

	    static K kdef(); // default K value 
	    static V vdef(); // default V value

	    void find(const K&);
	    void init() { sz = 0; head = 0; current = 0; }
	public:

	    Map() : def_key(kdef()), def_val(vdef())
	        { init(); }
	    Map(const K& k, const V& d) : def_key(k), def_val(d)
	        { init(); }
	    ~Map() { delete head; } // delete all links recursively

	    Map(const Map&);
	    Map& operator= (const Map&);

	    V& operator[] (const K&);

	    int size() const { return sz; }
	    void clear() { delete head; init(); }
	    void remove(const K& k);

	        // iteration functions:

	    Mapiter element(const K& k)
	    {
	        (void) operator[](k);  // move current to k
	        return Mapiter(this,current);
	    }
	    Mapiter first() { return Mapiter(this,head); }
	    Mapiter last();
	};

	template K Map::kdef()
	    { static K k; return k; }
	template V Map::vdef()
	    { static V v; return v; }
pg287: s/8.10 [2]/8.9 [4]/

pg289: add template before each of the iterator functions.

pg305: s/MININT -/MININT +/

pg316: delete comment on get()

pg354: s/char alloc;/short alloc;/

pg409: s/X::a/C::a/

pg418: s/i pg438: s/stream_iter/input_iter/

pg445: s/Base_iterator/base_iterator/

pg447: add to the declaration of base_iterator:

	    base_iterator(const base_iterator&);
	    base_iterator& operator=(const base_iterator&);

	replace base_iterator::base_iterator() definition with:

	base_iterator::base_iterator(const Type_info* bb, int direct)
	{
	    i = 0;
	
	    if (direct) { // use list of direct bases 
	        b = bb;
	        alloc = 0;
	        return;
	    }

	    // create list of all bases:

	    // int n = number of bases
	    b = new (Type_info*)[n+1];
	    alloc = 1;
	    // put bases into b
	}
pg448: replace definition of ptr_cast() and ref_cast() with:
	#define ptr_cast(T,p) \
	    (T::info().get_type_info()->can_cast((p)) ? (T*)(p) : 0)
	#define ref_cast(T,r) \
	    (T::info().get_type_info()->can_cast((r)) ? 0 : \
	      throw Bad_cast(T::info().get_type_info()->name()), (T&)(r))
pg449: s/dynamic_type()/info()/

s/static_type()/get_info()/

pg467: s/(*pf)()/(*pf)(void*)/

pg472: s/r.count/r.pcount/

pg474: s/(chunk_size-esize)/chunk_size/


New errata, not reflected in printings:

pg219: s/left =/left = (s->left) ? s->left->clone() : 0;

pg219: s/right =/right = (s->right) ? s->right->clone() : 0;

pg241: s/for (pp=/if (free) for(pp=/