(Click here for a personal note from Marshall Cline.)
C++ FAQ
/
Section 4
/ FAQ 4.42
Section 4:
4.1
Updates for the 03/12 release?
New!
4.2
Updates for the 11/11 release?
New!
4.3
Updates for the 07/11 release?
4.4
Updates for the 05/11 release?
4.5
Updates for the 03/11 release?
4.6
Updates for the 08/10 release?
4.7
Updates for the 06/10 release?
4.8
Updates for the 05/10 release?
4.9
Updates for the 04/10 release?
4.10
Updates for the 03/10 release?
4.11
Updates for the 01/10 release?
4.12
Updates for the 09/09 release?
4.13
Updates for the 06/09 release?
4.14
Updates for the 01/09 release?
4.15
Updates for the 03/07 release?
4.16
Updates for the 09/06 release?
4.17
Updates for the 03/06 release?
4.18
Updates for the 10/05 release?
4.19
Updates for the 07/05 release?
4.20
Updates for the 06/05 release?
4.21
Updates for the 05/05 release?
4.22
Updates for the 04/05 release?
4.23
Updates for the 03/05 release?
4.24
Updates for the 02/05 release?
4.25
Updates for the 12/04 release?
4.26
Updates for the 06/04 release?
4.27
Updates for the 08/03 release?
4.28
Updates for the 06/03 release?
4.29
Updates for the 05/03 release?
4.30
Updates for the 04/03 release?
4.31
Updates for the 03/03 release?
4.32
Updates for the 02/03 release?
4.33
Updates for the 01/03 release?
4.34
Updates for the 12/02 release?
4.35
Updates for the 09/02 release?
4.36
Updates for the 06/02 release?
4.37
Updates for the 05/02 release?
4.38
Updates for the 04/02 release?
4.39
Updates for the 03/02 release?
4.40
Updates for the 08/01 release?
4.41
Updates for the 04/01 release?
4.42
Updates for the 07/00 release?
4.43
Updates for the 03/00 release?
4.44
Updates for the 01/00 release?
4.45
Updates for the 10/99 release?
4.46
Updates for the 07/99 release?
4.47
Updates for the 06/98 release?
4.48
Updates for the 05/98 release?
4.49
Updates for the 09/97 release?
4.50
Updates for the 01/97 release?
4.51
Updates for the 11/96 release?
4.52
Updates for the 10/96 release?
4.53
Updates for the 09/96 release?
4.54
Updates for the 08/96 release?
4.55
Updates for the 07/96 release?
4.56
Updates for the 06/96 release?
4.57
Updates for the 05/96 release?
4.58
Updates for the 04/96 release?
4.59
Updates for the 03/96 release?
4.60
Updates for the 09/95 release?
4.61
Updates for the 06/95 release?
4.62
Updates for the 04/95 release?
4.63
Updates for the 03/95 release?
4.64
Updates for the 01/95 release?
4.65
Updates for the 12/94 release?
4.66
Updates for the 11/94 release?
4.67
Updates for the 08/94 release?
4.68
Updates for the 08/94 release?
[4.42] What updates were made for the 07/00 release?
Global changes:
Moved the main FAQ site to
www.parashift.com/c++-faq/
. (This was unfortunately necessary due to a business issue involving AT&T and the previous web hosting company, Cerf-Net.)
12 New FAQs:
[4.42] What updates were made for the 07/00 release?
(created)
[11.13] Should my destructor throw an exception when it detects a problem?
(created)
[15.9] But shouldn't I always use a
printOn()
method rather than a
friend
function?
(created)
[16.26] Can I use a garbage collector in C++?
(created thanks to
Hans Boehm
)
[16.27] What are the two kinds of garbage collectors for C++?
(created thanks to
Hans Boehm
)
[16.28] Where can I get more info on garbage collectors for C++?
(created)
[17.1] What are some ways
try
/
catch
/
throw
can improve software quality?
(created)
[17.9] How can I handle a destructor that fails?
(created)
[21.9] Perhaps Ellipse should inherit from Circle then?
(created)
[34.1] Why should I use container classes rather than simple arrays?
(created with help from
Stan Brown
)
[39.1] How do I convert a value (a number, for example) to a
std::string
?
(created thanks to
Rob Stewart
)
[39.2] How do I convert a
std::string
to a number?
(created thanks to
Rob Stewart
)
72 Changed FAQs:
[2.6] Where can I find the C++ FAQ translated into Chinese?
(updated the URL)
[3.1] Is there a
C++ FAQ Book
in addition to this on-line
C++ FAQ
?
(added
BookPool.com
and
AllDirect.com
thanks to
Stan Brown
, plus reorganized)
[3.2] Is there a big difference between this on-line
C++ FAQ
and the
C++ FAQ Book
?
(changed 'much' to 'many' thanks to
Stan Brown
)
[6.6] Who uses C++?
(rewrote)
[6.9] Are
virtual
functions (dynamic binding) central to OO/C++?
(inserted "the" before "difference" thanks to
Stan Brown
and reworded references to STL)
[6.12] Is C++ standardized?
Updated!
(changed "has been finalized" to "was finalized" thanks to
Stan Brown
)
[6.13] Where can I get a copy of the ANSI/ISO C++ standard?
(added URLs to free copies of CD2)
[9.5] Why should I use
inline
functions instead of plain old
#define
macros?
(rewrote the sentence on
#define
being evil)
[10.5] Which constructor gets called when I create an array of
Fred
objects?
(changed so it uses new-style headers and the
std::
syntax and reworded references to STL)
[10.8] What is the "Named Constructor Idiom"?
(fixed a typo (
Fred
vs.
Point
) in the prose thanks to
Roy LeCates
)
[12.3] OK, OK, already; I'll handle self-assignment. How do I do it?
(reworded the last paragraph)
[13.3] What are some examples of operator overloading?
(changed so it uses the
std::
syntax)
[13.6] Can I overload
operator==
so it lets me compare two
char[]
using a string comparison?
(changed so it uses the
std::
syntax)
[13.10] How do I create a subscript
operator
for a
Matrix
class?
(changed so it uses new-style headers and the
std::
syntax)
[13.13] Should I design my classes from the outside (interfaces first) or from the inside (data first)?
(changed so it uses new-style headers and the
std::
syntax and reworded references to STL)
[15.1] Why should I use
<iostream>
instead of the traditional
<cstdio>
?
(renamed "subclassable" to "inheritable" and revamped to use new-style headers)
[15.2] Why does my program go into an infinite loop when someone enters an invalid input character?
(changed so it uses new-style headers and the
std::
syntax)
[15.4] How does that funky
while (std::cin >> foo)
syntax work?
(changed so it uses new-style headers and the
std::
syntax)
[15.5] Why does my input seem to process past the end of file?
(changed so it uses new-style headers and the
std::
syntax)
[15.6] Why is my program ignoring my input request after the first iteration?
(changed so it uses new-style headers and the
std::
syntax)
[15.8] How can I provide printing for my
class
Fred
?
(changed so it uses new-style headers and the
std::
syntax)
[15.10] How can I provide input for my
class
Fred
?
(changed so it uses new-style headers and the
std::
syntax)
[15.11] How can I provide printing for an entire hierarchy of classes?
(changed so it uses new-style headers and the
std::
syntax)
[15.13] How can I "reopen"
std::cin
and
std::cout
in binary mode?
(changed so it uses new-style headers and the
std::
syntax)
[15.16] Why can't I open a file in a different directory such as
"..\test.dat"
?
(changed so it uses new-style headers and uses the
std::
syntax)
[16.6] Do I need to check for
NULL
after
p = new Fred()
?
(changed so it uses new-style headers and the
std::
syntax)
[16.7] How can I convince my (older) compiler to automatically check
new
to see if it returns
NULL
?
(changed the example to use
throw
rather than
abort()
thanks to
Stan Brown
; changed to use new-style headers and the
std::
syntax)
[16.14] After
p = new Fred[n]
, how does the compiler know there are
n
objects to be destructed during
delete[] p
?
(changed "popluar" to "popular" thanks to
Fabrice Clerc
)
[16.16] How do I allocate multidimensional arrays using
new
?
(fixed a leak in the third
manipulateArray()
by moving another
for
loop into the
try
block)
[16.17] But the previous FAQ's code is SOOOO tricky and error prone! Isn't there a simpler way?
(clarified the last paragraph)
[16.18] But the above
Matrix
class is specific to
Fred
! Isn't there a way to make it generic?
(rewrote)
[16.20] Does C++ have arrays whose length can be specified at run-time?
(changed so it uses new-style headers and the
std::
syntax and reworded references to STL)
[16.23] How do I provide reference counting with copy-on-write semantics?
(rewrote the first paragraph for clarity thanks to
Fabrice Clerc
)
[16.24] How do I provide reference counting with copy-on-write semantics for a hierarchy of classes?
(changed so it uses new-style headers and the
std::
syntax)
[17.11] How do I change the string-length of an array of
char
to prevent memory leaks even if/when someone throws an exception?
(rewrote the last half)
[18.1] What is "
const
correctness"?
(changed so it uses new-style headers and the
std::
syntax)
[18.2] How is "
const
correctness" related to ordinary type safety?
(changed so it uses new-style headers and the
std::
syntax)
[18.10] What is a "
const
member function"?
(removed a spurious ")" thanks to
Stan Brown
)
[18.15] Why does the compiler allow me to change an
int
after I've pointed at it with a
int const*
?
(changed so it uses new-style headers and the
std::
syntax)
[19.3] How do you express inheritance in C++?
(added "derived class of" to the list of synonyms)
[19.7] How can I protect derived classes from breaking when I change the internal parts of the base class?
(renamed "subclass" to "derived class")
[21.4] Is an array of
Derived
a kind-of array of
Base
?
(changed so it uses new-style headers and the
std::
syntax and reworded references to STL)
[21.5] Does array-of-
Derived
is-
not
-a-kind-of array-of-
Base
mean arrays are bad?
(changed so it uses new-style headers and the
std::
syntax and reworded references to STL)
[22.3] What is an ABC?
(renamed "subclass" to "derived class")
[22.4] What is a "pure virtual" member function?
(renamed "subclass" to "derived class")
[24.3] Which should I prefer: composition or private inheritance?
(changed so it uses new-style headers and the
std::
syntax)
[24.5] How is
protected
inheritance related to
private
inheritance?
(renamed "subclass" to "derived class")
[24.6] What are the access rules with
private
and
protected
inheritance?
(renamed "subclass" to "derived class")
[27.4] What's the difference between
<xxx>
and
<xxx.h>
headers?
(changed
<xyz.h>
to
<xxx.h>
and wordsmithed thanks to
Stan Brown
)
[27.6] Is the
?:
operator evil since it can be used to create unreadable code?
(changed so it uses new-style headers and the
std::
syntax)
[27.10] Are there any lint-like guidelines for C++?
(changed so it uses new-style headers and the
std::
syntax)
[27.12] Which is better: identifier names
that_look_like_this
or identifier names
thatLookLikeThis
?
(improved the precision and added the last two paragraphs thanks to
Chris Hurst
)
[27.13] Are there any other sources of coding standards?
(fixed some URLs thanks to
James S. Adelman
and
Stan Brown
)
[29.16] Why is floating point so inaccurate? Why doesn't this print 0.43?
(changed so it uses new-style headers and the
std::
syntax)
[30.4] How do you use inheritance in C++, and is that different from Smalltalk?
(renamed "subclass" to "derived class")
[30.5] What are the practical consequences of differences in Smalltalk/C++ inheritance?
(renamed "subclass" to "derived class")
[31.3] What's the difference between
virtual
data and dynamic data?
(renamed "subclass" to "derived class")
[31.8] Does the poor performance of reference semantics mean I should pass-by-value?
(renamed "subclass" to "derived class")
[34.2] How can I make a
perl
-like associative array in C++?
(changed so it uses new-style headers and the
std::
syntax)
[34.5] How can I insert/access/change elements from a linked list/hashtable/etc?
(reworded, plus changed so it uses new-style headers and the
std::
syntax)
[35.2] What's the syntax / semantics for a "class template"?
(changed so it uses new-style headers and the
std::
syntax)
[35.3] What's the syntax / semantics for a "function template"?
(changed so it uses new-style headers and the
std::
syntax)
[37.1] What is the "STL"?
(changed so it uses new-style headers and the
std::
syntax)
[37.2] Where can I get a copy of "STL"?
(added URLs for
the SGI implementation
and
STLport
thanks to
Stan Brown
)
[37.3] How can I find a
Fred
object in an STL container of
Fred*
such as
std::vector<Fred*>
?
(changed so it uses new-style headers and the
std::
syntax)
[38.5] Where can I get information about the C++ compiler from {Borland, IBM, Microsoft, Sun, etc.}?
(updated the URL for IBM VisualAge C++ thanks to
Rick Alther
; updated the URL for
GNU C++
thanks to
Martin Honnen
)
[39.4] What should be done with macros that contain
if
?
(added the last three paragraphs, including the link showing why we don't use
do {...} while (false)
)
[39.5] What should be done with macros that have multiple lines?
(changed "
if (1)
..." to "
if (true)
..." and "
do...while (0)
" to "
do...while (false)
")
[39.8] What are the C++ scoping rules for
for
loops?
(because the scoping rules for
for
loops are no longer "new" (thanks
Stan Brown
), rewote the FAQ)
[39.14] Why can't I put a forward-declared class in a
std::vector<>
?
(changed so it uses new-style headers and the
std::
syntax)
[40.3] Are there any pretty-printers that reformat C++ source code?
(added HPS Beauty)
[40.6] Why does my DOS C++ program says "Sorry: floating point code not linked"?
(added a cross reference and updated to new header syntax)