I am aware that in some compilers, you can set
new to throw an out of memory exception, rather than returning
NULL. I would think that your readers would find it somewhat confusing that from one page to the next, you change your mind which behavior you expect from the compiler.
On page 28, you rely on
new to return
NULL:
Code:
if (!newElem) return false;
On page 34, you state,
Quote:
|
An exception can be thrown when a memory allocation fails, which enables you to use the return value of pop for data instead of an error code.
|
And then you rely on that behavior in the
push function listed on Page 35.
It might be nicer for the reader if you make a more overt statement about which behavior of
new you expect, in any given example. Even better, state which version of
new you expect as a general assumption at the beginning of the book, and then specifically highlight when you rely on a different assumption.
Regards,
Matt