cout << r.operator double();
instead of
cout << Rational::operator double(r);
is.putback(c)
instead of
cin.putback(c)
const int MAX_SIZE(10);
is better than
int MAX_SIZE(10);
q + n = p
instead of
p + n = q
.
Semantically, the delete and delete[] operators:
by
Semantically, a delete or delete[] expression:
At the end of the third point, the following should be added:
... to the operating system (but this behaviour can be overriden by overloading the operator, see page 110).
operator<<(ostream&, const
String&)
:
return os << s.data();
instead of
return os << data();
Pool::dealloc(void*)
instead of
Pool::dealloc(Rational*)
.
Array<T>::Array(unsigned
int size)
:
template <typename T>
class Array {
Array(unsigned int size =10): data_(new T[size]), size_(size) {}
..
instead of (size_
is used before it is defined).
template <typename T>
class Array {
Array(unsigned int size =10): data_(new T[size_]), size_(size) {}
..
Array<T>::operator=(const Array& a)
:
if (this==&a) // self assignment
return *this;
instead of
if (this==&a) // self assignment
return;
String
should enforce
invariant data_.get() != 0
(don't allow 0 pointers as argument to init()
):
class String {
// A simple string class, implemented using auto_ptr.
public:
String(const char* cstring=""): data_(init(cstring?cstring:"")) {}
..
instead of
class String {
// A simple string class, implemented using auto_ptr.
public:
String(const char* cstring=0): data_(init(cstring)) {}
..
Dictionary::hash()
function should
not be static:
class Dictionary {
..
unsigned int hash(const string& s) { return scramble(s)%size_; }
};
instead of
class Dictionary {
..
static unsigned int hash(const string& s) { return scramble(s)%size_; }
};
da
variable, not to ad
.
getline(is,class_name)
instead of
(is>>class_name)
in the code for
PersistentObject::read
. This will properly read
the newline character written after the class name by
PersistentObject::write()
.
fd
in code (2nd line from
the bottom):
if (fd_ != -1) close(fd_);
instead of
if (fd != -1) close(fd_);
fd
in code:
~File() { if (fd_ != -1) close(fd_); }
instead of
~File() { if (fd != -1) close(fd_); }
static const string FORMAT_ERROR("not a number");
instead of
static const FORMAT_ERROR("not a number");
in Figure 11.3.