Addison-Wesley ISBN 0-201-92483-8
Using your existing knowledge of Fortran, C++ for Fortran Programmers gets you up and running with C++ quickly. By showing how individual elements of a Fortran program compare and translate into C++, this book helps you make a smooth transition to C++ and object-oriented concepts. Best-selling author and C++ authority Ira Pohl uses his trademark "dissection" technique to illustrate the underlying structure of programs and to help you understand design trade-offs. Scientific and engineering coding examples are featured throughout the text.
Features
You can buy this book online through Barnes and Noble.
If you are not conversant in Fortran or C, then the book C++ by Dissection is an excellent start for the professional programmer who wants to master C++ for use in an object-oriented environment. No knowledge of C is required. The author presents instruction in C++ using object-oriented methodology throughout.
The C++ code examples in the book are available in several forms. The code is arranged in directories corresponding to the chapters of the book. To get to the unpacked version for any system, or to get individual program files, you can use the FTP directory (www.cse.ucsc.edu/~pohl/FORTRAN/). Files are also available in zip form for Windows users and compressed tar form for UNIX users.
Additional C++ Code Examples
Ira has provided additional code to demonstrate dynamic cast, complete clock program, multiple inheritance, mutable members, string constructors, and rvalue vs. lvalue.
Errata
Some of these errata have been corrected in later printings. A note with the approximate month for the correction is at the end of any corrections which may already have been made.
Caveats: Some standard libraries may have been modified since this book was written and the function prototypes may differ from what is available on your compiler. Check your compiler vendor for the correct prototypes.
Notations:
p425 means page 425
+8 means 8 lines from top
-7
means 7 lines from bottom
If you encounter errata in this book not listed here, please contact Ira Pohl via email at pohl@cse.ucsc.edu with your errata. You will be cited in the correction if you are the first to report it.
CALL
and RETURN
and should
have subroutine first in standard Fortran.
Needs to be:
SUBROUTINE PRMSG (STR) CHARACTER * (*) STR IF (LEN(STR) .LT. 1) THEN PRINT *, 'Hello World!' ELSE PRINT *, STR END IF RETURN END PROGRAM WORLD CALL PRMSG('') END
Needs to be: int k = (rand() % (52 -
i));
stack
needs to be ch_stack
Needs to be: const ch_stack::int max_len;
//declaration required
class ch_stack
Needs to be: In file ch_stack4.h
stack
should be ch_stack
Needs to be: ch_stack (const ch_stack&
str); //copy constructor
Needs to be: Standard C does not have authentic multidimensional arrays. .... can implement flexible, safe, dynamic multidimensional arrays.
delete p[i]
statement should be changed so that it conforms to the delete syntax for arrays
allocated by new[]
.
Needs to be: delete []p[i]
The above correction has been made in later printings
stack
needs to be ch_stack
Needs to be: explicit ch_stack(int n);
//not used for conversion
Needs to be: page 176)
The above correction has been made in later printings
unsigned int
Needs to be: unsigned long
The above correction has been made in later printings
vect
example had ub()
as a member function.
Needs to be: Two sentences in the second paragraph
on page 226 need to be removed. They are "The public data member ub
is changed to a member function. This prevents a user from inadvertently intoducing
a program error by modifying the member."
vect operator=
needs to be in the class
Needs to be:
class vect { ... int& operator[](int i) const; //range checked element dbl_vect& operator=(const dbl_vect& v); //assignment ...
Needs to be: element-type& operator[](
integral type);
return (*this)
Needs to be: return *this
Explanation: It is the style of this book to not use parentheses with a simple return argument.
The above correction has been made in later printings
Needs to be: friend istream& operator
>>(istream& in, ratiional& x);
*this
Needs to be: return *this;
ptr
Needs to be: return ptr;
Explanation: This program has been added to the website.
Explanation: This program was erroneously a copy of new_hdler.cpp. The over_new.cpp file has been corrected to flesh out the example code as found on page 228.
*this
Needs to be: { this -> tick(); return
*this; }
j != 0
Needs to be: j >= 0
The above correction has been made in later printings
p + size
is incorrect; need bp + size
instead
Needs to be: This is why the member function
vector::end()
returns bp + size
.
Needs to be: The benefits of this parameterization include allocation off the stack
p[i]
Needs to be: return p[i];
front
Needs to be: return front;
gentree
should be gen_tree
Needs to be: The generic tree type gen_tree
...
cin
and {
.
Needs to be: while (cin >> dat) {
Class
(uppercase incorrect)
Needs to be: class
The above correction has been made in later printings
int i= 0
Needs to be: for (int i = 0; i < how_many
- 2; ++i)
init(odd);
call should be removed. The first call to update(odd, even)
creates (inits)
odd
, when no dele(odd)
has yet been called. The code as is will
leave a little pile of lost heap memory lying around.Change the line with init(odd);
init(even);
Needs to be: init(even);
plans
Needs to be: class student_worker
The above correction has been made in later printings
public virtual
person
Needs to be: virtual public person
Explanation: While public virtual
and virtual public
are both allowed interchangeably, the preferred
style is virtual public
.
The above correction has been made in later printings
public virtual
student
Needs to be: virtual public person
Explanation: While public virtual
and virtual public
are both allowed interchangeably, the preferred
style is virtual public
. The class which is inherited from was incorrect
and needs to be person
, not student
.
The above correction has been made in later printings
class::student
and class::worker
Needs to be: class student
and
class worker
The above correction has been made in later printings
Needs to be: ! ~
Needs to be: ! ~
BOOLEAN
needs
semicolon for consistency with the other typedefs
Needs to be: typedef int BOOLEAN;
int
not needed before b
.
Needs to be: int a = -5, b = 3, c = 0;
p452 (C. L. Tondo) line 4-5: In keeping with
general style of using const
for arguments which won't be changed,
the constructors should use const
Needs to be:
dbl_vect_bnd(const dbl_vect_bnd& v); //copy constructor dbl_vect_bnd(const dbl_vect& v); //conversion constructor ..... //conversion constructor dbl_vect_bnd::dbl_vect_bnd(const dbl_vect& v) : dbl_vect(v), l_bnd(0), u_bnd(size - 1) { } //copy constructor dbl_vect_bnd::dbl_vect_bnd(const dbl_vect_bnd& v) : dbl_vect(v), l_bnd(v.l_bnd), u_bnd(v.u_bnd) { }
Base*
and Derived
should be switched.
Needs to be:
class Base { .....}; class Derived : Base { ..... }; void fcn(Base* ptr) { Derived* bptr = dynamic_cast <Derived*>(ptr);
In this example, the case converts the pointer value
ptr
to a Derived*
.
The above correction has been made in later printings
Class
(uppercase incorrect)
Needs to be: class
The above correction has been made in later printings
Needs to be: int good():
const
from void
Needs to be: operator void*() const;
Class
(uppercase incorrect)
Needs to be: class
The above correction has been made in later printings
p509 line 2: seven constructors
Needs to be: six constructors
p509 line 3-4: Two conversions were removed from the standard. Delete sentence "Two of these ..."
String Constructor Members table entries 3 and 5: Two conversions were removed from the standard. Delete
string(const vector...) string(size_t size, ...)
String Constructor Members table: One conversion
was added to the standard. Insert in place of string(const vector...)
string(InputIterator b, InputIterator e)
constructor from the InputInterator
range b
to e
Last Item in String Constructor Members table has
order of arguments reversed. string(char c, size_t n = 1)
is incorrect
and cannot have the default argument.
Needs to be: string(size_t n, char c)
Third table entry from bottom of String overloaded
Operator Members, operator vector<
... should be removed
order of arguments reversed. append(char c, size_t
n = 1)
is incorrect and cannot have the default argument.
Needs to be: append(size_t n, char c)
order of arguments reversed. assign(char c, size_t
n = 1)
is incorrect and cannot have the default argument.
Needs to be: assign(size_t n, char c)
order of arguments reversed. insert(char c, size_t
n = 1)
is incorrect and cannot have the default argument.
Needs to be: insert(size_t n, char c)
needs another assign at end of assigns list
Needs to be: string& assign(InputIterator
b, InputIterator e);
needs 3 more inserts at end of inserts list:
iterator insert(iterator p, char c); iterator insert(iterator p, size_t n, char c); void insert(iterator p, InputIterator b, InputIterator e);
Second table entry in String Members table has string&
replace(pos, n, c, rep = 1);
The rep argument has been removed.
Needs to be: string& rplace(pos, n, c);
and the comment "repeated rep
times" needs to be removed.
Third table entry from bottom in String Members table
has comment returns the private member res
; the first function resets
this which needs to be modified.
Needs to be: allocates memory for string; returns the size of the allocation
Third and fourth table entries in String Members
table and their explanations should be removed. The two items for removal are:
char get_at(pos) const;
and void put_at(pos, c);
int compare (const char* p, size_t pos) const
which needs a default value on last argument.
Needs to be: int compare (const char*
p, size_t pos = 0) const
int compare (char c, size_t pos, size_t rep =
1) const;)
which must be removed altogether.
The above correction has been made in later printings