Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7
---

C++ FAQ (part 2 of 7)

---
From: mpcline@nic.cerf.net (Marshall Cline)
Newsgroups: comp.lang.c++,comp.answers,news.answers
Subject: C++ FAQ (part 2 of 7)
Followup-To: comp.lang.c++
Date: 17 Jan 1997 19:04:30 GMT
Organization: Paradigm Shift, Inc (technology consulting)
Sender: cline@parashift.com
Expires: +1 month
Message-ID: <5boifu$lq3@news.cerf.net>
Reply-To: cline@parashift.com (Marshall Cline)
Summary: Please read this before posting to comp.lang.c++

Archive-name: C++-faq/part2
Posting-Frequency: monthly
Last-modified: Jan 1, 1997
URL: http://www.cerfnet.com/~mpcline/c++-faq-lite/

AUTHOR: Marshall Cline / cline@parashift.com / Paradigm Shift, Inc. /
One Park St. / Norwood, NY 13668 / 315-353-6100 (voice) / 315-353-6110 (fax)

COPYRIGHT: This posting is part of "C++ FAQ Lite."  The entire "C++ FAQ Lite"
document is Copyright(C) 1991-96 Marshall P. Cline, Ph.D., cline@parashift.com.
All rights reserved.  Copying is permitted only under designated situations.
For details, see section [1].

NO WARRANTY: THIS WORK IS PROVIDED ON AN "AS IS" BASIS.  THE AUTHOR PROVIDES NO
WARRANTY WHATSOEVER, EITHER EXPRESS OR IMPLIED, REGARDING THE WORK, INCLUDING
WARRANTIES WITH RESPECT TO ITS MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR
PURPOSE.

C++-FAQ-Lite != C++-FAQ-Book: This document, C++ FAQ Lite, is not the same as
the C++ FAQ Book.  The book (C++ FAQs, Cline and Lomow, Addison-Wesley) is 500%
larger than this document, and is available in bookstores.  For details, see
section [3].

==============================================================================

SECTION [4]: Recent changes to this document


[4.1] What updates were made for the 01/97 release? [NEW!]

[Recently created (on 1/97).]

Global changes:
 * Added the (much requested!) one-click download feature[2.2].  This
   automagically sends you a copy of the entire FAQ so you can browse off-line.
   There's a similar feature to get a copy of the "plaintext" version of the
   FAQ[2.3].
 * Removed those pesky "hit counters" from each HTML page.
 * Added nifty forward and backward links just after each FAQ.
 * Added more nifty navigation aids at the bottom of each page.
 * Renamed section [6] from "Management Issues" to "Big Picture Issues."

New FAQs:
 * [4.1] What updates were made for the 01/97 release?
 * [15.2] Why does my program go into an infinite loop when someone enters an
   invalid input character?
 * [15.3] How does that funky while (cin >> foo) syntax work?
 * [16.16] But the previous FAQ's code is SOOOO tricky and error prone! Isn't
   there a simpler way?
 * [25.4] Is the ?: operator evil since it can be used to create unreadable
   code?

Changed FAQs:
 * [1.3] Copying Permissions
   (simplified)
 * [2.1] Where's the closest mirror site to access this document?
   (removed the "USA-2" site)
 * [2.2] How can I get a Copy of all the HTML files of C++ FAQ Lite so I can
   read them Off-Line?
   (rewrote and added a one-click feature to get .zip, .tar.Z or .tar.gz
format)
 * [2.3] How can I get a Copy of all the "plaintext" files of C++ FAQ Lite so I
   can read them Off-Line?
   (rewrote and added a one-click feature to get .zip, .tar.Z or .tar.gz
format)
 * [5.1] What does IMHO mean? (or IMO, IMNSHO, FWIW, OTOH, etc.)?
   (added KUTGW (thanks to Bengt Richter))
 * [15.6] How can I provide printing for my class Fred?
   (added note about cascading operator<< calls)
 * [15.7] How can I provide input for my class Fred?
   (added note about cascading operator<< calls)
 * [16.6] How can I convince my (older) compiler to automatically check new to
   see if it returns NULL?
   (fixed bugs: new handlers don't take arguments, thanks to Scott Aaron;
changed set_new_hanlder to set_new_handler, thanks to Peter Andersson)
 * [16.15] How do I allocate multidimensional arrays using new?
   (rewritten and expanded with a rectangular-matrix case)
 * [18.1] What is "const correctness"?
   (rewrote because of helpful feedback from Nor Jaidi)
 * [21.6] Is a Circle a kind-of an Ellipse?
   (added a caveat that setSize(x,y) isn't sacred)
 * [21.7] Are there other options to the "Circle is/isnot kind-of Ellipse"
   dilemma?
   (added a caveat that setSize(x,y) isn't sacred)
 * [21.8] But I have a Ph.D. in Mathematics, and I'm sure a Circle is a kind of
   an Ellipse! Does this mean Marshall Cline is stupid? Or that C++ is stupid?
   Or that OO is stupid?
   (added a caveat that setSize(x,y) isn't sacred)
 * [23.1] When my base class's constructor calls a virtual function, why
   doesn't my derived class's override of that virtual function get invoked?
   (rewrote)
 * [29.8] How can I pass an object of a C++ class to/from a C function?
   (added #ifndef FRED_H / #define FRED_H to code)
 * [33.3] Where can I get information about the C++ compiler from {Borland,
   IBM, Microsoft, Semantic, Sun, etc.}?
   (added HP C++)
 * [35.4] Where can I get OS-specific questions answered (e.g., BC++, DOS,
   Windows, etc)?
   (added Borland C++ URLs thanks to Simon Edlund)

==============================================================================

[4.2] What updates were made for the 11/96 release? [NEW!]

[Recently created (on 11/96).]

New FAQs:
 * [2.2] How can I get a Copy of all the HTML files of C++ FAQ Lite so I can
   read them Off-Line?
 * [4.2] What updates were made for the 11/96 release?
 * [20.3] What's the difference between how virtual and non-virtual member
   functions are called?
 * [33.1] How do I display text in the status bar using MFC?
   (with the help of Paul Ganney)

Changed FAQs:
 * [8.4] How can you reseat a reference to make it refer to a different object?
   (changed last line from "pointer to const" to "const pointer" thanks to
Neelesh Pandit)
 * [25.10] Are there any other sources of coding standards?
   (rewrote and added more URLs)
 * [33.6] If name mangling was standardized, could I link code compiled with
   compilers from different compiler vendors?
   (reworded and added v-table and v-pointer references[20.3])

==============================================================================

[4.3] What updates were made for the 10/96 release?

New FAQs:
 * [4.3] What updates were made for the 10/96 release?

Changed FAQs:
 * [5.8] Which newsgroup should I post my questions?
   (added comp.sys.mac.programmer.* and comp.sys.mac.oop.*)
 * [16.6] How can I convince my (older) compiler to automatically check new to
   see if it returns NULL?
   (added comments on constructors of globals; thanks to William Carroll
carrolw@ttc.com)
 * [25.10] Are there any other sources of coding standards?
   (added URLs)
 * [33.3] Where can I get information about the C++ compiler from {Borland,
   IBM, Microsoft, Semantic, Sun, etc.}?
   (added URL for Metrowerks and Watcom compilers)

==============================================================================

[4.4] What updates were made for the 09/96 release?

New FAQs:
 * [4.4] What updates were made for the 09/96 release?
 * [5.1] What does IMHO mean? (or IMO, IMNSHO, FWIW, OTOH, etc.)?
 * [5.2] How do I get comp.lang.c++ to do my homework problem for me?
 * [5.3] What should I do if I see someone else posting a homework problem?
   (with the help of Phil Staite pstaite@vnet.ibm.com)
 * [18.4] What does "const Fred* p" mean?
 * [18.5] What's the difference between "const Fred* p", "Fred* const p" and
   "const Fred* const p"?
 * [18.6] What does "const Fred& x" mean?
 * [18.7] Does "Fred& const x" make any sense?
 * [18.8] What does "Fred const& x" mean?
 * [18.13] Does "const Fred* p" mean that *p can't change?
 * [25.10] Are there any other sources of coding standards?
 * [33.2] How can I decompile an executable program back into C++ source code?
   (with the help of Phil Staite pstaite@vnet.ibm.com)

Changed FAQs:
 * [8.4] How can you reseat a reference to make it refer to a different object?
   (added a cross reference regarding pointer to const[18.4])
 * [9.4] How do you tell the compiler to make a non-member function inline?
   (strengthened the "Note:" at the end)
 * [16.18] How can I force objects of my class to always be created via new
   rather than as locals or global/static objects?
   (reworded and added a paragraph on using friend[14] to soften the original
goal)
 * [16.20] How do I provide reference counting with copy-on-write semantics?
   (added links to the self assignment[12.1] discussion)
 * [16.21] How do I provide reference counting with copy-on-write semantics for
   a hierarchy of classes?
   (added links to the self assignment[12.1] discussion)
 * [17.2] How should I handle resources if my constructors may throw
   exceptions?
   (added cross-references for reference-counted[16.19] and remote[13.3]
smart-pointers)
 * [21.2] Derived* --> Base* works OK; why doesn't Derived** --> Base** work?
   (fixed a bug with help from William Wu)
 * [22.4] What is a "pure virtual" member function?
   (reworded)
 * [32.3] Where can I get help on how to use STL?
   (fixed the URL for Kenny Zalewski's STL guide)
 * [33.3] Where can I get information about the C++ compiler from {Borland,
   IBM, Microsoft, Semantic, Sun, etc.}?
   (added URLs for Silicon Graphics and Symantec compilers)
 * [35.2] Are there any pretty-printers that reformat C++ source code?
   (added a URL for "V Communications")

==============================================================================

[4.5] What updates were made for the 08/96 release?

Global changes:
 * Recently added/changed FAQs are now chained together using hyper-links
   (mainly for those who want to find out what has changed since the last time
   they read this document; only available in the HTML version)
 * Recently added FAQs are now decorated with [NEW!] ("recently" = "in the
   current or previous release")
 * Recently changed FAQs are now decorated with [UPDATED!] ("recently" = "in
   the current or previous release")
 * The look-and-feel of hyper-linked cross references is changed (NOTE: this
   change ONLY shows up in the HTML version)
   - The old look-and-feel "looks like this[4.5]"
   - The new look-and-feel "looks like this[4.5]"
 * Added section [12] Assignment operators
 * Added section [26] Learning OO/C++

New FAQs:
 * [4.5] What updates were made for the 08/96 release?
 * [7.3] When is an interface "good"?
 * [7.4] What is encapsulation?
 * [7.5] How does C++ help with the tradeoff of safety vs. usability?
 * [9.2] How can inline functions help with the tradeoff of safety vs. speed?
 * [12.1] What is "self assignment"?
 * [12.2] Why should I worry about "self assignment"?
 * [12.3] OK, OK, already; I'll handle self-assignment.  How do I do it?
 * [13.3] What are some examples of operator overloading?
 * [15.10] Why can't I open a file in a different directory such as
   "..\test.dat"?
 * [26.1] What is mentoring?
 * [26.2] Should I learn C before I learn OO/C++?
 * [26.3] Should I learn Smalltalk before I learn OO/C++?
 * [26.4] Should I buy one book, or several?
 * [26.5] What are some best-of-breed C++ morality guides?
 * [26.6] What are some best-of-breed C++ legality guides?
 * [26.7] Are there other OO books that are relevant to OO/C++?
 * [33.3] Where can I get information about the C++ compiler from {Borland,
   IBM, Microsoft, Semantic, Sun, etc.}?

Changed FAQs:
 * [6.4] Is C++ better than Ada? (or Visual Basic, C, FORTRAN, Pascal,
   Smalltalk, or any other language?)
   (reworded the last paragraph)
 * [6.6] How long does it take to learn OO/C++?
   (added management-level hints for training developers in OO/C++)
 * [9.3] Why should I use inline functions? Why not just use plain old #define
   macros?
   (moved)
 * [13.4] But operator overloading makes my class look ugly; isn't it supposed
   to make my code clearer?
   (rewritten)
 * [13.8] How do I create a subscript operator for a Matrix class?
   (fixed a bug: "double** data_" is now "double* data_")
 * [25.8] Are there any lint-like guidelines for C++?
   (added links to the self assignment[12.1] discussion)
 * [26.6] What are some best-of-breed C++ legality guides?
   (fixed the ISBN for Stan Lippman's book)
 * [27.1] What's the difference between C++ and Smalltalk?
   (rewritten)
 * [32.4] How can you tell if you have a dynamically typed C++ class library?
   (moved from the section on Smalltalk[27])
 * [32.5] What is the NIHCL? Where can I get it?
   (moved from the section on Smalltalk[27])
 * [32.8] Where can I get tons and tons of more information on C++ class
   libraries?
   (updated the URL)
 * [34.1] Why can't the compiler find my header file in
   #include "c:\test.hpp" ?
   (updated to refer to [15.10])

==============================================================================

[4.6] What updates were made for the 07/96 release?

Global changes:
 * Created an extensive subject index
 * Added hyper-linked internal cross references throughout (mainly useful for
   the HTML version)
 * 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 [29] How to mix C and C++

New FAQs:
 * [4.6] What updates were made for the 07/96 release?
 * [5.5] What do I do if someone else posts a question that's already in the
   FAQ?
 * [5.6] What makes a good Subject: line?
 * [6.8] Are virtual functions (dynamic binding) central to OO/C++?
 * [6.9] I'm from Missouri.  Can you give me a simple reason why virtual
   functions (dynamic binding) make a big difference?
 * [7.6] How can I prevent other programmers from violating encapsulation by
   seeing the private parts of my class?
 * [7.7] Is Encapsulation a Security device?
 * [10.4] Is the default constructor for Fred always Fred::Fred()?
 * [10.5] Which constructor gets called when I create an array of Fred objects?
 * [10.6] What is the "Named Constructor Idiom"?
 * [10.7] Why can't I initialize my static member data in my constructor's
   initialization list?
 * [11.2] What's the order that local objects are destructed?
 * [11.3] What's the order that objects in an array are destructed?
 * [11.4] Can I overload the destructor for my class?
 * [11.5] Should I explicitly call a destructor on a local variable?
 * [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?
 * [11.7] OK, OK already; I won't explicitly call the destructor of a local;
   but how do I handle the above situation?
 * [11.8] What if I can't wrap the local in an artificial block?
 * [11.9] But can I explicitly call a destructor if I've allocated my object
   with new?
 * [11.10] What is "placement new" and why would I use it?
 * [11.11] When I write a destructor, do I need to explicitly call the
   destructors for my member objects?
 * [13.6] Can I overload operator== so it lets me compare two char[] using a
   string comparison?
 * [13.8] How do I create a subscript operator for a Matrix class?
 * [13.9] Should I design my classes from the outside (interfaces first) or
   from the inside (data first)?
 * [15.7] How can I provide input for my class Fred?
 * [16.5] Do I need to check for NULL after p = new Fred()?
 * [16.6] How can I convince my (older) compiler to automatically check new to
   see if it returns NULL?
 * [16.7] Do I need to check for NULL before delete p?
 * [16.8] What are the two steps that happen when I say delete p?
 * [16.9] In p = new Fred(), does the Fred memory "leak" if the Fred
   constructor throws an exception?
 * [16.12] Can I drop the [] when deleteing array of some built-in type (char,
   int, etc)?
 * [16.13] After p = new Fred[n], how does the compiler know there are n
   objects to be destructed during delete[] p?
 * [16.19] How do I do simple reference counting?
 * [16.20] How do I provide reference counting with copy-on-write semantics?
 * [16.21] How do I provide reference counting with copy-on-write semantics for
   a hierarchy of classes?
 * [17.3] How do I change the string-length of an array of char to prevent
   memory leaks even if/when someone throws an exception?
 * [18.12] Why does the compiler allow me to change an int after I've pointed
   at it with a const int*?
 * [22.5] How do you define a copy constructor or assignment operator for a
   class that contains a pointer to a (abstract) base class?
 * [23.4] What does it mean that the "virtual table" is an unresolved external?
 * [25.9] Which is better: identifier names that_look_like_this or identifier
   names thatLookLikeThis?
   (with the help of James Robinson james-robinson@uiowa.edu)
 * [29.1] What do I need to know when mixing C and C++ code?
 * [30.5] How can I avoid syntax errors when calling a member function using a
   pointer-to-member-function?
 * [31.1] How can I make a perl-like associative array in C++?
 * [32.2] How can I find a Fred object in an STL container of Fred* such as
   vector<Fred*>?
 * [32.8] Where can I get tons and tons of more information on C++ class
   libraries?
 * [33.4] How do compilers use "over-allocation" to remember the number of
   elements in an allocated array?
 * [33.5] How do compilers use an "associative array" to remember the number of
   elements in an allocated array?
 * [34.1] Why can't the compiler find my header file in
   #include "c:\test.hpp" ?
 * [34.2] Does C++ have new scoping rules for for loops?

Changed FAQs:
 * [5.4] How can I find out about general netiquette so I don't embarrass
   myself?
   (rewritten)
 * [5.7] How do I post a question about code that doesn't work correctly?
   (rewritten)
 * [7.8] What's the difference between the keywords struct and class?
   (rewritten)
 * [10.8] 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.6] How can I provide printing for my class Fred?
   (added example code to illustrate operator<< on an ostream)
 * [15.8] How can I provide printing for an entire hierarchy of classes?
   (moved from the section on Abstraction[22])
 * [16.18] 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[10.6])
 * [29.2] How can I include a standard C header file in my C++ code?
   (rewritten)
 * [29.3] How can I include a non-system C header file in my C++ code?
   (rewritten)
 * [29.4] How can I modify my own C header files so it's easier to #include
   them in C++ code?
   (rewritten)
 * [33.8] Is there a yacc-able C++ grammar?
   (updated the URL for the yacc-able C++ grammar)
 * [35.2] Are there any pretty-printers that reformat C++ source code?
   (added "C-Clearly" and GNU indent to the list of pretty-printers)

==============================================================================

[4.7] What updates were made for the 06/96 release?

New FAQs:
 * [4.7] What updates were made for the 06/96 release?
 * [10.2] Is there any difference between List x; and List x();?
 * [34.5] Why is floating point so inaccurate? Why doesn't this print 0.43?
   (with the help of Phil Staite pstaite@vnet.ibm.com)

Changed FAQs:
 * [2.1] Where's the closest mirror site to access this document?
   (added Finland mirror site: http://www.utu.fi/~sisasa/oasis/cppfaq/)
 * [3.2] Is this on-line ("Lite") document the same as the C++ FAQ Book?
   (fixed URL of book at Addison-Wesley)
 * [3.3] How can I download a free copy of the C++ FAQ Book?
   (fixed URL of book at Addison-Wesley)
 * [18.1] What is "const correctness"?
   (added info on what happens when you try to pass a const parameter to a
non-const function)
 * [20.4] When should my destructor be virtual?
   (added the nitty-gritty rule for when you need to have a virtual destructor)
 * [21.4] Is an array of Derived a kind-of array of Base?
   (fixed bug in code)
 * [22.3] What is an ABC?
   (reworded)
 * [22.4] What is a "pure virtual" member function?
   (reworded)
 * [28.4] Should I normally use pointers to freestore allocated objects for my
   data members, or should I use "composition"?
   (reworded)
 * [29.8] How can I pass an object of a C++ class to/from a C function?
   (fixed a bug in the code)
 * [31.4] What's the idea behind templates?
   (reworded)
 * [31.6] What's the syntax / semantics for a "class template"?
   (reworded)
 * [35.1] Is there a TeX or LaTeX macro that fixes the spacing on "C++"?
   (added a new LaTeX macro)
 * [35.2] Are there any pretty-printers that reformat C++ source code?
   (fixed URL of C++2LaTeX)

==============================================================================

[4.8] What updates were made for the 05/96 release?

Updated everything.  Transformed the source from raw text to HTML.
Reorganized, reworded, expanded, added example code, etc, etc.

==============================================================================

[4.9] What updates were made for the 04/96 release?

New FAQs:
 * [4.9] What updates were made for the 04/96 release?
 * [29.2] How can I include a standard C header file in my C++ code?
 * [29.3] How can I include a non-system C header file in my C++ code?
 * [29.4] How can I modify my own C header files so it's easier to #include
   them in C++ code?

Changed FAQs:
 * [2.1] Where's the closest mirror site to access this document?
   (added European mirror site:
http://www.informatik.uni-konstanz.de/~kuehl/cpp/cppfaq.htm)
 * [16.14] Is it legal (and moral) for a member function to say delete this?
   (rewritten)
 * [22.4] What is a "pure virtual" member function?
   (rewritten)

==============================================================================

[4.10] What updates were made for the 03/96 release?

New FAQs:
 * [4.10] What updates were made for the 03/96 release?
 * [6.4] Is C++ better than Ada? (or Visual Basic, C, FORTRAN, Pascal,
   Smalltalk, or any other language?)
 * [31.2] How can I build a <favorite container> of objects of different types?
   (with the help of Phil Staite pstaite@vnet.ibm.com)

Changed FAQs:
 * [2.3] How can I get a Copy of all the "plaintext" files of C++ FAQ Lite so I
   can read them Off-Line?
   (added URL ftp://rtfm.mit.edu/pub/usenet-by-group/comp.lang.c++/)
 * [6.12] Where can I get a copy of the latest ANSI/ISO-C++ draft standard?
   (fixed the URL for the ANSI/ISO-C++ Committee Draft)
 * [15.1] Why should I use <iostream.h> instead of the traditional <stdio.h>?
   (reworded)
 * [16.2] Can I free() pointers allocated with new? Can I delete pointers
   allocated with malloc()?
   (added an admonition not to mix new and free() or malloc() and delete)
 * [25.1] What are some good C++ coding standards?
   (reworded)
 * [25.2] Are coding standards necessary? Are they sufficient?
   (reworded)
 * [25.3] Should our organization determine coding standards from our C
   experience?
   (reworded)
 * [25.8] Are there any lint-like guidelines for C++?
   (reworded)
 * [27.3] Which is a better fit for C++: "static typing" or "dynamic typing"?
   (updated info on dynamic_cast and typeid())
 * [35.2] Are there any pretty-printers that reformat C++ source code?
   (fixed URL of C++2LaTeX)

==============================================================================

[4.11] What updates were made for the 09/95 release?

New FAQs:
 * [4.11] What updates were made for the 09/95 release?
 * [15.9] How can I "reopen" cin and cout in binary mode under DOS and/or OS/2?
 * [32.3] Where can I get help on how to use STL?
 * [32.6] Where can I ftp the code that accompanies "Numerical Recipes"?
 * [32.7] Why is my executable so large?

Changed FAQs:
 * [6.12] Where can I get a copy of the latest ANSI/ISO-C++ draft standard?
   (added info on FTP access for the ANSI/ISO-C++ Committee Draft)
 * [8.3] What happens if you return a reference?
   (fixed a bug (variable i was not declared))
 * [16.15] How do I allocate multidimensional arrays using new?
   (reworded)
 * [32.1] Where can I get a copy of "STL"?
   (reworded)

==============================================================================

[4.12] What updates were made for the 06/95 release?

New FAQs:
 * [4.12] What updates were made for the 06/95 release?
 * [16.15] How do I allocate multidimensional arrays using new?
   (with the help of Doug Shapter)
 * [30.3] Why do I keep getting compile errors (type mismatch) when I try to
   use a member function as an interrupt service routine?

Changed FAQs:
 * [6.12] Where can I get a copy of the latest ANSI/ISO-C++ draft standard?
   (fixed the US-Mail access for the ANSI/ISO-C++ Committee Draft)
 * [16.18] How can I force objects of my class to always be created via new
   rather than as locals or global/static objects?
   (rewritten)

==============================================================================

[4.13] What updates were made for the 04/95 release?

New FAQs:
 * [4.13] What updates were made for the 04/95 release?
 * [35.4] Where can I get OS-specific questions answered (e.g., BC++, DOS,
   Windows, etc)?

Changed FAQs:
 * [32.5] What is the NIHCL? Where can I get it?
   (fixed the FTP address)

==============================================================================

[4.14] What updates were made for the 03/95 release?

New FAQs:
 * [4.14] What updates were made for the 03/95 release?
 * [15.4] Why does my input seem to process past the end of file?
 * [15.5] Why is my program ignoring my input request after the first
   iteration?
 * [16.14] Is it legal (and moral) for a member function to say delete this?

Changed FAQs:
 * [35.3] Is there a C++-mode for GNU emacs? If so, where can I get it?
   (updated the information on cc-mode.el)

==============================================================================

[4.15] What updates were made for the 01/95 release?

New FAQs:
 * [2.4] Where can I download a Chinese translation of this on-line document?
 * [4.15] What updates were made for the 01/95 release?

==============================================================================

[4.16] What updates were made for the 12/94 release?

New FAQs:
 * [4.16] What updates were made for the 12/94 release?
 * [32.1] Where can I get a copy of "STL"?
 * [33.6] If name mangling was standardized, could I link code compiled with
   compilers from different compiler vendors?

Changed FAQs:
 * [24.3] Which should I prefer: composition or private inheritance?
   (reworded)

==============================================================================

[4.17] What updates were made for the 11/94 release?

New FAQs:
 * [3.1] Is there a C++ FAQ Book I can buy in a bookstore?
 * [3.2] Is this on-line ("Lite") document the same as the C++ FAQ Book?
 * [3.3] How can I download a free copy of the C++ FAQ Book?
 * [3.4] Why would I spend good money on a book when I can download it for
   free?
 * [4.17] What updates were made for the 11/94 release?

==============================================================================

[4.18] What updates were made for the 08/94 release?

Rewrote most of the answers to provide general cleanup.  Changed the quotation
marks to "..." rather than `...' and/or ``...''.  Sample code lines now start
with a tab (no other lines starts with a tab).  Everything was edited; minor
modifications everywhere.

New FAQs:
 * [4.18] What updates were made for the 08/94 release?
 * [18.10] What do I do if I want to update an "invisible" data member inside a
   const member function?
 * [27.3] Which is a better fit for C++: "static typing" or "dynamic typing"?

==============================================================================

[4.19] What updates were made before 08/94?

This document was originally written in 1991.  I have no record of the specific
changes that were made until 8/94.

==============================================================================

SECTION [5]: Netiquette when posting to comp.lang.c++


[5.1] What does IMHO mean? (or IMO, IMNSHO, FWIW, OTOH, etc.)? [UPDATED!]

[Recently added KUTGW (thanks to Bengt Richter) (on 1/97).]

Here's a partial list of acronyms in alphabetical order:
 * BTW = By the way
 * FWIW = For what it's worth
 * FYI = For your information
 * IMHO = In my humble opinion (egoless)
 * IMNSHO = In my not-so humble opinion (a lot of ego)
 * IMO = In my opinion (a little ego)
 * KUTGW = Keep Up The Good Work
 * MYOB = Mind your own business
 * OTOH = On the other hand
 * RTFM = Read the ___ manual
 * SO = Significant other (as in, "My SO and I went for a walk...")

==============================================================================

[5.2] How do I get comp.lang.c++ to do my homework problem for me?

Shame on you!

Please do not post your homework questions to comp.lang.c++.

==============================================================================

[5.3] What should I do if I see someone else posting a homework problem?

When a slackard[5.2] asks comp.lang.c++ to do their homework for them,
answering their question is the worst thing for them.  Please don't do it!
Instead you can use the following table of "frequently asked homework
assignments" to give them a hint/pointer:

===TABLE-BEGIN=== (yea, I know; it's pathetic; the HTML version is better)

===TABLE-ROW===
If someone asks...
---
...then here's a brief answer:

===TABLE-ROW===
How do I do Equation Parsing in C++?
---
Use a stack of operators to convert infix to postfix, then a stack of operands
to evaluate the postfix expression.

===TABLE-ROW===
How do I do Shortest Path in C++?
---
Look up Dijkstra's algorithm and backtracking.

===TABLE-ROW===
How do I do Sorting in C++?
---
Look up heapsort, quicksort, merge sort, internal and external sorting.

===TABLE-ROW===
How do I do Minimum Spanning Trees in C++?
---
Look up Kruskal and/or Prim's algorithm.

===TABLE-ROW===
How do I do Combinations and/or Permutations in C++?
---
See your algorithms book.

===TABLE-ROW===
How do I do <some small essay problem; obviously contrived for a school
assignment; too well defined to to be from the real world> in C++?
---
Do it yourself. If you get stuck, ask a specific question.

===TABLE-END===

[If anyone has other suggestions that should go into this table, please let me
know; thanks; (cline@parashift.com)].

==============================================================================

[5.4] How can I find out about general netiquette so I don't embarrass myself?

Key guidelines:
 * Do not say, "Please respond by e-mail because I don't normally read this
   newsgroup".  If you don't have enough time for the newsgroup, don't expect
   the newsgroup to have enough time for you.
 * Do not post questions that are answered in the newsgroup's FAQ.  That's like
   saying your time (to read the FAQ) is more valuable than the time of
   hundreds and hundreds of others (to answer your question).  Tres uncool.
   Read the FAQ first![5.5]
 * Do not cross post your question to a big pile of newsgroups.  Post to the
   newsgroup (singular) that best fits your question[5.8].  If you don't get an
   answer in the "right" newsgroup, post somewhere else but redirect followups
   back to the "right" newsgroup.
 * Do include a working e-mail address in your signature.  If your From:
   address is not correct, please notify your system administrator.  Until it's
   fixed, add a Reply-to: line that gives your correct e-mail address.

Many more general netiquette questions are answered in the newsgroup
news.announce.newusers.  This newsgroup contains many must-read articles for
new users.

==============================================================================

[5.5] What do I do if someone else posts a question that's already in the FAQ?

Please don't answer a question that's already in the FAQ.  Instead politely but
firmly point the questioner to the FAQ using the following template:

    Subject: It's in the FAQ (was: Original_Subject_Goes_Here)

    > Original_Question_Goes_Here [...]

    This issue is covered in the C++ FAQ.
    You can get the FAQ at:
        http://www.cerfnet.com/~mpcline/c++-faq-lite/

    Please read the FAQ.

If you're willing to help in this effort, consider yourself "deputized" to
point people to the FAQ using something like the above template.  With your
help, hopefully we can improve the signal-to-noise ratio on comp.lang.c++ and
thereby preserve it as a valuable resource.

Note #1: Please don't give them the location of the appropriate FAQ.  E.g.,
don't say, "Look at FAQ [10.3]" or "Look in section [10]".  It's the old
give-them-a-fish vs. teach-them-to-fish problem.

Note #2: Please be polite.  I'm hoping we can avoid "RTFM" or "RTFFAQ"
euphemisms (or worse!).

Thanks for any help you can give in this matter.

==============================================================================

[5.6] What makes a good Subject: line?

Be descriptive:
 * Bad: "Subject: HELP"
 * Bad: "Subject: C++ problem"
 * Bad: "Subject: SEX SEX SEX"
 * Good: "Subject: Problem new'ing a multi-dimensional array"

Mention your compiler/version if you think it's relevant.

==============================================================================

[5.7] How do I post a question about code that doesn't work correctly?

Key guidelines:

 1. Post compile'able code: avoid ellipses, such as void f() { ... }

 2. Post complete code: put in all necessary #includes and declarations of
    needed types and functions

 3. Post minimal code: just enough to demonstrate the problem; skip I/O and
    calls to libraries if possible

 4. Post one compilation unit: if possible, combine Foo.h into Foo.cpp

 5. Post the tools you used: compiler name, version number, operating system,
    etc

 6. Post the tool options you used: libraries, exact compiler and linker
    options, etc

 7. Post the exact messages you received; differentiate between compiler,
    linker, and runtime messages

As always, make sure your question isn't already in the FAQ.  Use the subject
index to check.

==============================================================================

[5.8] Which newsgroup should I post my questions?

Only post to comp.lang.c++ if your question is about the C++ language itself.
For example, C++ code design, syntax, style, rules, bugs, etc.
Operating-specific questions (e.g., about Windows NT / 95 / 3.x, UNIX, etc.)
should go to an operating-system-specific newsgroup (see below), not to
comp.lang.c++.

Here are some other potentially relevant newsgroups:
 * comp.lang.c++.moderated
   - A moderated variant of comp.lang.c++
   - The moderator's job is to keep the signal-to-noise ratio higher than in
     comp.lang.c++
 * comp.object
   - Mostly OO design issues, with less emphasis on OO programming)
   - That group's FAQ contains an excellent introduction to OO along with an
     overview of OO terms and concepts
 * comp.std.c++
   - Discussion directly related to the evolving ANSI/ISO C++ standard
   - The evolving ANSI/ISO C++ standard is discussed below
 * comp.os.ms-windows.programmer.tools
   - This group is intended for discussions about the selection and use of
     tools for Windows software development
 * comp.os.ms-windows.programmer.misc
   - This group is for all other discussions about Windows software development
   - There's one FAQ list for all the comp.os.ms-windows.programmer.* groups
   - Sample topic: Accessing C++ classes in a DLL
   - Sample topic: A dialog as an MDI child window [with OWL]
   - Sample topic: Disabled menu choices become enabled [with MFC]
   - Sample topic: Using STRICT with windows.h
   - Sample topic: A programmer's bibliography
 * comp.os.msdos.programmer
   - Much of the traffic is about language products, chiefly from Borland and
     Microsoft
   - Note: The FAQ for this group is not available at rtfm.mit.edu; it is at
     ftp://oak.oakland.edu/pub/msdos/info and ftp://garbo.uwasa.fi/pc/doc-net
   - Sample topic: How can I read a character without [waiting for] the Enter
     key?
   - Sample topic: How can I read, create, change, or delete the volume label?
   - Sample topic: How do I configure a COM port and use it to transmit data?
   - Sample topic: How can a C program send control codes to my printer?
   - Sample topic: How can I find the Microsoft mouse position and button
     status?
   - Sample topic: How can I write a TSR (terminate-stay-resident) utility?
   - Sample topic: How can I contact [Borland, Microsoft]?
 * comp.os.msdos.programmer.turbovision
   - Borland's character-mode framework
 * comp.unix.programmer
   - Sample topic: How do I use popen() to open a process for reading and
     writing?
   - Sample topic: How do I sleep() in a C program for less than one second?
 * comp.unix.solaris
   - Covers SunOS 4.x and Solaris
   - Sample topic: Signal Primer
   - Sample topic: Waiting for Children to Exit
 * gnu.g++.help
   - Sample topic: Where can I find a demangler?
   - Sample topic: Getting gcc/g++ binaries for Solaris 2.x
   - Sample topic: What documentation exists for g++ 2.x?
 * comp.sys.mac.programmer.* and comp.sys.mac.oop.*
   - Macintosh issues
 * gnu.g++.bug
   - Bug reports for g++; see the g++ docs
 * comp.lang.c
   - FAQ is posted monthly, and is maintained by Steve Summit, scs@eskimo.com
   - Sample topic: I'm confused.  NULL is guaranteed to be 0, but the null
     pointer is not?
   - Sample topic: So what is meant by the "equivalence of pointers and arrays"
     in C?
   - Sample topic: Why doesn't printf("%d\n", i++ * i++); work?
   - Sample topic: How can I write a function that takes a variable number of
     arguments? [stdarg.h or varargs.h]
   - Sample topic: How do I declare an array of pointers to functions returning
     pointers to functions returning pointers to characters?
 * comp.graphics
   - Issues revolving around graphics programming
 * comp.sources.wanted
   - If you want some source code for something, post your request there
 * comp.programming
   - General programming issues

==============================================================================

[5.9] How do I get the FAQs for a particular newsgroup?

Let me count the ways...

FAQs (Frequently Asked Questions lists) are available 24-hours a day via:
 * ftp or WWW: ftp://rtfm.mit.edu/pub/usenet/
 * e-mail: send a message with the line "help" to mail-server@rtfm.mit.edu
 * usenet: many FAQs are available in the newsgroup news.answers

Please, PLEASE do not send e-mail to me!

==============================================================================

SECTION [6]: Big Picture issues


[6.1] Is C++ a practical language?

Yes.

C++ is a practical tool.  It's not perfect[6.2], but it's useful.

In the world of industrial software, C++ is viewed as a solid, mature,
mainstream tool.  It has widespread industry support which makes it "good" from
an overall business perspective.

==============================================================================

[6.2] Is C++ a perfect language?

Nope.

C++ wasn't designed to demonstrate what a perfect OO language looks like.  It
was designed to be a practical tool for solving real world problems.  It has a
few warts, but the only place where it's appropriate to keep fiddling with
something until it's perfect is in a pure academic setting.  That wasn't C++'s
goal.

==============================================================================

[6.3] What's the big deal with OO?

Object-oriented techniques are the best way we know of to develop large,
complex software applications and systems.

OO hype: the software industry is "failing" to meet demands for large, complex
software systems.  But this "failure" is actually due to our successes: our
successes have propelled users to ask for more.  Unfortunately we created a
market hunger that the "structured" analysis, design and programming techniques
couldn't satisfy.  This required us to create a better paradigm.

C++ is an OO programming language.  C++ can also be used as a traditional
programming language (as "as a better C").  However if you use it "as a better
C," don't expect to get the benefits of object-oriented programming.

==============================================================================

[6.4] Is C++ better than Ada? (or Visual Basic, C, FORTRAN, Pascal, Smalltalk,
      or any other language?)

This question generates much much more heat than light.  Please read the
following before posting some variant of this question.

In 99% of the cases, programming language selection is dominated by business
considerations, not by technical considerations.  Things that really end up
mattering are things like availability of a programming environment for the
development machine, availability of runtime environment(s) for the deployment
machine(s), licensing/legal issues of the runtime and/or development
environments, availability of trained developers, availability of consulting
services, and corporate culture/politics.  These business considerations
generally play a much greater role than compile time performance, runtime
performance, static vs. dynamic typing, static vs. dynamic binding, etc.

Anyone who argues in favor of one language over another in a purely technical
manner (i.e., who ignores the dominant business issues) exposes themself as a
techie weenie, and deserves not to be heard.

==============================================================================

[6.5] Who uses C++?

Lots and lots of companies and government sites.  Lots.

The number of C++ developers doubles every year.  You can imagine that five
people are becomming C++ developers while you read this FAQ.

Growth is one of several critical features of C++[6.7].

==============================================================================

[6.6] How long does it take to learn OO/C++?

Companies like Paradigm Shift, Inc. info@parashift.com successfully teach
standard industry "short courses," where we compress a university semester
course into one 40 hour work week.  But regardless of where you get your
training, make sure the courses have a hands-on element, since most people
learn best when they have projects to help the concepts "gel." But even if they
have the best training, they're not ready yet.

It takes 6-12 months to become proficient in OO/C++.  Less if the developers
have easy access to a "local" body of experts, more if there isn't a "good"
general purpose C++ class library available.  To become one of these experts
who can mentor others takes around 3 years.

Some people never make it.  You don't have a chance unless you are teachable
and have personal drive.  As a bare minimum on "teachability," you have to be
able to admit when you've are wrong.  As a bare minimum on "drive," you must be
willing to put in some extra hours (it's a lot easier to learn some new facts
than it is to change your paradigm [i.e., to change the way you think; to
change your notion of goodness; to change your mental model of the world of
technology]).

Two things you should do:
 * Bring in a "mentor"[26.1]
 * Get your people two books: one to tell them what is legal[26.6], another to
   tell them what is moral[26.5]

Two things you should not do:
 * Don't bother having your people trained in C as a stepping-stone to learning
   OO/C++[26.2]
 * Don't bother having your people trained in Smalltalk as a stepping-stone to
   learning OO/C++[26.3]

==============================================================================

[6.7] What are some features of C++ from a business perspective?

Here are a few features of OO/C++ from a business perspective:
 * C++ has a huge installed base[6.5], which means you'll have multi-vendor
   support for tools, environments, consulting services, etc.[6.4], plus you'll
   have a very valuable line-item on your resume
 * C++ lets developers provide simplified interfaces[7.3] to software chunks,
   which improves the defect-rate when those chunks are (re)used
 * C++ lets you exploit developer's intuition through operator
   overloading[13.2], which reduces the learning curve for (re)users
 * C++ localizes access[7.4] to a software chunk, which reduces the cost of
   changes.
 * C++ reduces the safety-vs.-usability tradeoff[7.5], which improves the cost
   of (re)using a chunk of software.
 * C++ reduces the safety-vs.-speed tradeoff[9.2], which improves defect rates
   without degrading performance.
 * C++ gives you inheritance and dynamic binding[6.8] which let old code call
   new code[6.9], making it possible to quickly extend/adapt your software to
   hit narrow market windows.

==============================================================================

[6.8] Are virtual functions (dynamic binding) central to OO/C++?

Yes!

Without virtual functions[20], C++ is just a syntactic variant of C.  Operator
overloading[13] and non-virtual member functions are great, but they are, after
all, just syntactic sugar for the more typical C notion of passing a pointer to
a struct to a function.

From a business perspective, C++ without virtual functions has very little
value-add over straight C.  Technical people often think that there is a large
difference between C and non-OO C++, but without OO, difference usually isn't
enough to justify the cost of training developers, new tools, etc.  In other
words, if I were to advise a manager regarding whether to switch from C to
non-OO C++ (i.e., to switch languages but not paradigms), I'd probably
discourage him or her unless there were compelling tool-oriented reasons.  From
a business perspective, OO can help make systems extensible andadaptable, but
just the syntax of C++ classes without OO may not even reduce the maintenance
cost, and it surely adds to the training cost significantly.

Bottom line: C++ without virtual is not OO.  Programming with classes but
without dynamic binding is called "object based," but not "object oriented."
Throwing out virtual functions is the same as throwing out OO.  All you have
left is object-based programming, similar to the original Ada language (the new
Ada language, by the way, supports true OO rather than just object-based
programming).

==============================================================================

[6.9] I'm from Missouri.  Can you give me a simple reason why virtual functions
      (dynamic binding) make a big difference?

Overview: Dynamic binding can improve reuse by letting old code call new code.

Before OO came along, reuse was accomplished by having new code call old code.
For example, a programmer might write some code that called some reusable code
such as printf().

With OO, reuse can also be accomplished by having old code call new code.  For
example, a programmer might write some code that is called by a framework that
was written by their great, great grandfather.  There's no need to change
great-great-grandpa's code.  In fact, it doesn't even need to be recompiled.
Even if all you have left is the object file and the source code that
great-great-grandpa wrote was lost 25 years ago, that ancient object file will
call the new extension without anything falling apart.

That is extensibility, and that is OO.

==============================================================================

[6.10] Is C++ backward compatible with ANSI/ISO-C?

Almost.

C++ is as close as possible to compatible with C, but no closer.  In practice,
the major difference is that C++ requires prototypes, and that f() declares a
function that takes no parameters (in C, f() is the same as f(...)).

There are some very subtle differences as well, like sizeof('x') is equal to
sizeof(char) in C++ but is equal to sizeof(int) in C.  Also, C++ puts structure
"tags" in the same namespace as other names, whereas C requires an explicit
struct (e.g., the typedef struct Fred Fred; technique still works, but is
redundant in C++).

==============================================================================

[6.11] Are there any C++ standardization efforts underway?

Yes; ANSI (American) and ISO (International) groups are working closely with
each other.  The ANSI-C++ committee is called "X3J16".  The ISO C++ standards
group is called "WG21".  The major players in the ANSI/ISO C++ standards
process includes just about everyone:

AT&T, IBM, DEC, HP, Sun, MS, Borland, Zortech, Apple, OSF, etc ad nauseum.
Dozens of people attend each meeting.  People come from USA, UK, Japan,
Germany, Sweden, Denmark, France, ... (all have "local" committees sending
official representatives and conducting "local" meetings).

==============================================================================

[6.12] Where can I get a copy of the latest ANSI/ISO-C++ draft standard?

The ISO Committee Draft for C++ and the ANSI C++ Draft (the document that is
going out for public review) is available from:
 * http://www.cygnus.com/~mrs/wp-draft

You can also get Postscript and Adobe Acrobat versions from:
 * ftp://research.att.com/dist/c++std/WP
 * ftp://ftp.maths.warwick.ac.uk:/pub/c++/std/WP
 * ftp://ftpt.su.edu.au:/pub/C++/CommitteeDraft

You can get HTML and ASCII versions:
 * ftp://ftp.cygnus.com/pub/g++

You can also get a paper copy from:
 * Lynn Barra <lbarra@itic.nw.dc.us>
 * Ask for the latest version of "Draft Proposed American National Standard for
   Information Systems -- Programming Language C++" which is document number
   CD14882
 * It is typically shipped 2-day FedEx within the continental US

You can also order a paper copy via snail-mail:
 * X3 Secretariat
   1250 Eye Street NW
   Suite 200
   Washington, DC 20005
   202-626-5738
 * Ask for the latest version of "Draft Proposed American National Standard for
   Information Systems -- Programming Language C++" which is document number
   CD14882
 * It is typically shipped 2-day FedEx within the continental US

==============================================================================

-- 
Marshall Cline, Ph.D., President, Paradigm Shift, Inc.
315-353-6100 (voice)
315-353-6110 (fax)
mailto:cline@parashift.com



Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7

------------------------------------------------
[ By Archive-name | By Author | By Category | By Newsgroup ]
[ Home | Latest Updates | Archive Stats | Search | Usenet References | Help ]

------------------------------------------------

Send corrections/additions to the FAQ Maintainer:
cline@parashift.com (Marshall Cline)

Last Update August 12 1997 @ 02:02 AM

faq-admin@faqs.org