(Click here for a personal note from Marshall Cline.)
C++ FAQ
/
Section 4
/ FAQ 4.55
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.55] What updates were made for the 07/96 release?
Global changes:
Created an extensive
subject index
Added hyper-linked internal cross references throughout
Changed the name of the document from
On-Line C++ FAQs
to
C++ FAQs Lite
Created section
[23] Inheritance — what your mother never told you
Split sections
[10] Constructors
and
[11] Destructors
into two distinct sections
Major reorganization of sections
[19] Inheritance — basics
,
[20] Inheritance —
virtual
functions
,
[21] Inheritance — proper inheritance and substitutability
, and
[22] Inheritance — abstract base classes (ABCs)
Added example code throughout section
[32] How to mix C and C++
50 New FAQs:
[4.55] What updates were made for the 07/96 release?
(created)
[5.5] What do I do if someone else posts a question that's already in the FAQ?
(created)
[5.7] What makes a good
Subject:
line?
(created)
[6.9] Are
virtual
functions (dynamic binding) central to OO/C++?
(created)
[6.10] I'm from Missouri. Can you give me a simple reason why
virtual
functions (dynamic binding) make a big difference?
(created)
[7.6] How can I prevent other programmers from violating encapsulation by seeing the
private
parts of my class?
(created)
[7.8] Is Encapsulation a Security device?
(created)
[10.4] Is the default constructor for
Fred
always
Fred::Fred()
?
(created)
[10.5] Which constructor gets called when I create an array of
Fred
objects?
(created)
[10.8] What is the "Named Constructor Idiom"?
(created)
[10.11] Why can't I initialize my
static
member data in my constructor's initialization list?
(created)
[11.2] What's the order that local objects are destructed?
(created)
[11.3] What's the order that objects in an array are destructed?
(created)
[11.4] Can I overload the destructor for my class?
(created)
[11.5] Should I explicitly call a destructor on a local variable?
(created)
[11.6] What if I want a local to "die" before the close
}
of the scope in which it was created? Can I call a destructor on a local if I
really
want to?
(created)
[11.7] OK, OK already; I won't explicitly call the destructor of a local; but how do I handle the situation from the previous FAQ?
(created)
[11.8] What if I can't wrap the local in an artificial block?
(created)
[11.9] But can I explicitly call a destructor if I've allocated my object with
new
?
(created)
[11.10] What is "placement
new
" and why would I use it?
(created)
[11.11] When I write a destructor, do I need to explicitly call the destructors for my member objects?
(created)
[13.6] Can I overload
operator==
so it lets me compare two
char[]
using a string comparison?
(created)
[13.10] How do I create a subscript
operator
for a
Matrix
class?
(created)
[13.13] Should I design my classes from the outside (interfaces first) or from the inside (data first)?
(created)
[15.10] How can I provide input for my
class
Fred
?
(created)
[16.6] Do I need to check for
NULL
after
p = new Fred()
?
(created)
[16.7] How can I convince my (older) compiler to automatically check
new
to see if it returns
NULL
?
(created)
[16.8] Do I need to check for
NULL
before
delete p
?
(created)
[16.9] What are the two steps that happen when I say
delete p
?
(created)
[16.10] In
p = new Fred()
, does the
Fred
memory "leak" if the
Fred
constructor throws an exception?
(created)
[16.13] Can I drop the
[]
when
delete
ing an array of some built-in type (
char
,
int
, etc)?
(created)
[16.14] After
p = new Fred[n]
, how does the compiler know there are
n
objects to be destructed during
delete[] p
?
(created)
[16.22] How do I do simple reference counting?
(created)
[16.23] How do I provide reference counting with copy-on-write semantics?
(created)
[16.24] How do I provide reference counting with copy-on-write semantics for a hierarchy of classes?
(created)
[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?
(created)
[18.15] Why does the compiler allow me to change an
int
after I've pointed at it with a
int const*
?
(created)
[22.5] How do you define a copy constructor or assignment
operator
for a class that contains a pointer to a (abstract) base class?
(created)
[23.10] What does it mean that the "virtual table" is an unresolved external?
(created)
[27.12] Which is better: identifier names
that_look_like_this
or identifier names
thatLookLikeThis
?
(created with the help of
James Robinson
)
[32.1] What do I need to know when mixing C and C++ code?
(created)
[33.5] How can I avoid syntax errors when creating pointers to members?
(created)
[33.6] How can I avoid syntax errors when calling a member function using a pointer-to-member-function?
(created)
[34.2] How can I make a
perl
-like associative array in C++?
(created)
[37.3] How can I find a
Fred
object in an STL container of
Fred*
such as
std::vector<Fred*>
?
(created)
[37.9] Where can I get tons and tons of more information on C++ class libraries?
(created)
[38.7] How do compilers use "over-allocation" to remember the number of elements in an allocated array?
(created)
[38.8] How do compilers use an "associative array" to remember the number of elements in an allocated array?
(created)
[39.7] Why can't the compiler find my header file in
#include "c:\test.h"
?
(created)
[39.8] What are the C++ scoping rules for
for
loops?
(created)
13 Changed FAQs:
[5.4] How can I find out about general netiquette so I don't embarrass myself?
(rewritten)
[5.8] How do I post a question about code that doesn't work correctly?
(rewritten)
[7.9] What's the difference between the keywords
struct
and
class
?
(rewritten)
[10.12] Why are classes with
static
data members getting linker errors?
(rewritten)
[11.12] When I write a derived class's destructor, do I need to explicitly call the destructor for my base class?
(added example code to illustrate the compiler's automagic calls to destructors of member objects and base class subobjects)
[15.8] How can I provide printing for my
class
Fred
?
(added example code to illustrate
operator<<
on an
ostream
)
[15.11] How can I provide printing for an entire hierarchy of classes?
(moved from the section on
Abstraction
)
[16.21] How can I force objects of my class to always be created via
new
rather than as locals or global/
static
objects?
(added a reference to the
Named Constructor Idiom
)
[32.2] How can I include a standard C header file in my C++ code?
(rewritten)
[32.3] How can I include a non-system C header file in my C++ code?
(rewritten)
[32.4] How can I modify my own C header files so it's easier to
#include
them in C++ code?
(rewritten)
[38.11] Is there a
yacc
-able C++ grammar?
(updated the URL for the
yacc
-able C++ grammar)
[40.3] Are there any pretty-printers that reformat C++ source code?
(added "C-Clearly" and GNU
indent
to the list of pretty-printers)