(Click here for a personal note from Marshall Cline.)
C++ FAQ
/
Section 4
/ FAQ 4.34
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.34] What updates were made for the 12/02 release?
Big-picture changes:
Added a new section on
Multiple and Virtual Inheritance
.
Added a new section on
Serialization
.
Added
New!
and
Updated!
tags on the section titles.
34 New FAQs:
[4.34] What updates were made for the 12/02 release?
(created)
[13.14] How can I overload the prefix and postfix forms of operators
++
and
--
?
(created thanks to
Sandeep Grover
)
[13.15] Which is more efficient:
i++
or
++i
?
(created)
[15.12] How can I open a stream in binary mode?
(created thanks to
Simon Barner
)
[15.14] How can I write/read objects of my class to/from a data file?
(created)
[15.15] How can I send objects of my class to another computer (e.g., via a socket, TCP/IP, FTP, email, a wireless link, etc.)?
(created)
[19.8] I've been told to never use protected data, and instead to always use private data with protected access functions. Is that a good rule?
(created thanks to a question from
Andrew Chan
)
[19.9] Okay, so exactly how should I decide whether to build a "
protected
interface"?
(created)
[21.11] How could "it depend"??!? Aren't terms like "Circle" and "Ellipse" defined mathematically?
(created)
[25.1] How is this section organized?
(created)
[25.2] I've been told that I should never use multiple inheritance. Is that right?
(created)
[25.3] So there are times when multiple inheritance isn't bad?!??
(created)
[25.4] What are some disciplines for using multiple inheritance?
(created)
[25.5] Can you provide an example that demonstrates the above guidelines?
(created)
[25.6] Is there a simple way to visualize all these tradeoffs?
(created)
[25.7] Can you give another example to illustrate the above disciplines?
(created)
[25.11] What special considerations do I need to know about when I use virtual inheritance?
(created)
[25.12] What special considerations do I need to know about when I inherit from a class that uses virtual inheritance?
(created)
[25.13] What special considerations do I need to know about when I
use
a class that uses virtual inheritance?
(created)
[25.14] One more time: what is the exact order of constructors in a multiple and/or virtual inheritance situation?
(created thanks to
Carl Daniel
)
[33.10] Can I convert a pointer-to-member-function to a
void*
?
(created)
[33.11] Can I convert a pointer-to-function to a
void*
?
(created)
[35.13] How can I avoid linker errors with my template functions?
Updated!
(created thanks to a suggestion by
Michael Kochetkov
)
[35.15] How can I avoid linker errors with my template classes?
Updated!
(created thanks to a suggestion by
Michael Kochetkov
)
[36.1] What's this "serialization" thing all about?
(created thanks to a question from
Stephen Tashiro
)
[36.2] How do I select the best serialization technique?
(created)
[36.7] How do I serialize objects that aren't part of an inheritance hierarchy and that don't contain pointers to other objects?
(created)
[36.8] How do I serialize objects that are part of an inheritance hierarchy and that don't contain pointers to other objects?
(created)
[36.9] How do I serialize objects that contain pointers to other objects, but those pointers form a tree with no cycles and no joins?
(created)
[36.10] How do I serialize objects that contain pointers to other objects, but those pointers form a tree with no cycles and only "trivial" joins?
(created)
[36.11] How do I serialize objects that contain pointers to other objects, and those pointers form a graph that might have cycles or non-trivial joins?
(created thanks to a question from
Stephen Tashiro
)
[36.12] Are there any caveats when serializing / unserializing objects?
(created)
[36.13] What's all this about graphs, trees, nodes, cycles, joins, and joins at the leaves vs. internal nodes?
(created)
[39.3] Can I templatize the above functions so they work with other types?
(inspired by
Merlyn Morgan-Graham
)
21 Changed FAQs:
[5.2] How do I get other people to do my homework problem for me?
(added the "serious bodily harm" quote thanks to
Jack Klein
)
[5.4] How can I find out about general netiquette so I don't embarrass myself?
(added the joke/quote about top-posting)
[6.15] What does the FAQ mean by "such and such is
evil
"?
(fixed a typo in the last paragraph thanks to
YaoJun
)
[10.18] Do I need to worry about the "
static
initialization order fiasco" for variables of built-in/intrinsic types?
(added
std::
prefix on
cout
thanks to
Thomas Tutone
)
[13.1] What's the deal with
operator
overloading?
(changed parameter types from by-value to by-reference-to-const)
[15.13] How can I "reopen"
std::cin
and
std::cout
in binary mode?
(removed references to DOS and OS/2)
[15.16] Why can't I open a file in a different directory such as
"..\test.dat"
?
(moved/renumbered)
[29.3] Should I use
void main()
or
int main()
?
(fixed parameter-order mistake thanks to
Chris Young
and many others)
[29.17] Why doesn't my floating-point comparison work?
(reworded)
[33.2] How do I pass a pointer-to-member-function to a signal handler, X event callback, system call that starts a thread/task, etc?
(shortened some names to make it easier to read)
[33.5] How can I avoid syntax errors when creating pointers to members?
(renamed the macro to all-caps)
[33.6] How can I avoid syntax errors when calling a member function using a pointer-to-member-function?
(renamed the macro to all-caps)
[33.7] How do I create and use an array of pointer-to-member-function?
(renamed the macro to all-caps)
[35.12] Why can't I separate the definition of my templates class from its declaration and put it inside a .cpp file?
(added the caveat at the beginning; wordsmithed throughout)
[37.4] Where can I get help on how to use STL?
(added Rogue Wave's STL Guide thanks to
Richard van Wegen
)
[37.8] Why is my executable so large?
(added the paragraph on debugging thanks to
Richard van Wegen
; rewrote the second paragraph)
[38.1] Where can I download a free C++ compiler?
(added several new links thanks to
Thomas Tutone
)
[39.1] How do I convert a value (a number, for example) to a
std::string
?
(fixed a typo in the last paragraph thanks to
Alex Rutchka
, rewrote the code examples to use exceptions, and moved it from
the I/O section
)
[39.2] How do I convert a
std::string
to a number?
(rewrote the code examples to use exceptions, added the
failIfLeftoverChars
, and moved it from
the I/O section
)
[39.4] What should be done with macros that contain
if
?
(reworded in various spots)
[39.5] What should be done with macros that have multiple lines?
(reworded)