Archive-name: C++-faq/part03
Posting-Frequency: monthly Last-modified: Jun 17, 2002 URL: http://www.parashift.com/c++-faq-lite/ See reader questions & answers on this topic! - Help others by sharing your knowledge AUTHOR: Marshall Cline / cline@parashift.com / 972-931-9470 COPYRIGHT: This posting is part of "C++ FAQ Lite." The entire "C++ FAQ Lite" document is Copyright(C)1991-2002 Marshall 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 06/02 release? [NEW!] [Recently created (in 6/02).] Big-picture changes: * Added a new section on Newbie Questions / Answers[28]. New FAQs: * [4.1] What updates were made for the 06/02 release? * [6.14] What does the FAQ mean by "such-in-such is evil"? * [21.11] If SortedList has exactly the same public interface as List, is SortedList a kind-of List? (thanks to a conversation with Dave Mikesell) * [25.12] How can I tell if an integer is a power of two without looping? (thanks to S.K. Mody) * [28.1] What is this "newbie section" all about? * [28.2] Where do I start? Why do I feel so confused, so stupid? (thanks to a question from John Lester) * [28.3] What are the criteria for choosing between short / int / long data types? (thanks to a question from John Lester) * [28.4] What the heck is a const variable? Isn't that a contradiction in terms? (thanks to a question from John Lester) * [28.5] Why would I use a const variable / const identifier as opposed to #define? (thanks to a question from John Lester) * [28.6] Are you saying that the preprocessor is evil? * [28.7] What is the "standard library"? What is included / excluded from it? (thanks to a question from John Lester) * [28.8] How should I lay out my code? When should I use spaces, tabs, and/or newlines in my code? (thanks to a question from John Lester) * [28.9] Is it okay if a lot of numbers appear in my code? * [28.10] What's the point of the L, U and f suffixes on numeric literals? (thanks to a question from John Lester) * [28.11] I can understand the and (&&) and or (||) operators, but what's the purpose of the not (!) operator? (thanks to a question from John Lester) * [28.12] Is !(a < b) logically the same as a >= b? * [28.13] What is this NaN thing? * [28.14] What is the type of an enumeration such as enum Color? Is it of type int? (thanks to a question from John Lester) * [28.15] If an enumeration type is distinct from any other type, what good is it? What can you do with it? (thanks to a question from John Lester) * [35.6] What's the difference between C++ and Visual C++? (based on a question from Lavanya Mahashankar) Changed FAQs: * [2.7] Where can I download a Portuguese translation of the C++ FAQ Lite? (updated the URL) * [3.1] Is there a C++ FAQ Book in addition to the C++ FAQ Lite? (changed the URL for the book cover <http://www.awprofessional.com/content/images/0201309831/0201309831.jpg> and excerpts <http://www.awl.com/cseng/titles/0-201-30983-1> thanks to Thomas Hansen; also added the sample chapter <http://www.awprofessional.com/content/images/0201309831/samplechapter/clinepref.pdf> and source code <http://www.awprofessional.com/content/images/0201309831/sourcecode/readme.htm>.) * [5.6] Wait a minute, does that previous FAQ say to not answer their question just because it's already answered in the FAQ?!? (fixed misspelling in "cripple" thanks to John Marshall plus general rewording) * [5.13] What about spam? (fixed a typo thanks to Paul Savage) * [10.6] Should my constructors use "initialization lists" or "assignment"? (added symmetry argument wrt non-static const members thanks to Tanmoy Bhattacharya) * [10.13] Why doesn't the construct-on-first-use idiom use a static object instead of a static pointer? (made substantive changes to the second-to-last paragraph thanks to Amitha Perera and Wil Evers) * [18.10] What do I do if I want a const member function to make an "invisible" change to a data member? (reworded the question to distinguish "invisible change" from "invisible data member" thanks to Thomas Hansen) * [25.4] But, but, but what about machines where a char has more than 8 bits? Surely you're not saying a C++ byte might have more than 8 bits, are you?!? (removed a superfluous statement thanks to Gennaro Prota) * [25.6] I'm sooooo confused. Would you please go over the rules about bytes, chars, and characters one more time? (rewrote; changed the example from the mythical FOO machine to a PDP-10, plus added words showing how to simulate pointers using software, much thanks to Andrew Koenig) * [25.7] What is a "POD type"? (added note that POD types can contain non-virtual member functions thanks to Andrew Koenig) * [25.8] When initializing non-static data members of built-in / intrinsic / primitive types, should I use the "initialization list" or assignment? (clarified the cross-reference) * [25.9] When initializing static data members of built-in / intrinsic / primitive types, should I worry about the "static initialization order fiasco"? (made it clearer that the FAQ provides a solution) * [35.5] Where can I get information about the C++ compiler from {Borland, IBM, Microsoft, Sun, etc.}? (updated the link to KAI C++) ============================================================================== [4.2] What updates were made for the 05/02 release? [NEW!] [Recently created (in 5/02).] Big-picture changes: * Added a new section on built-in / intrinsic / primitive data types[25]. * Updated the link to the Portuguese translation <http://www.arnaut.eti.br/op/CPPFL00.htm>. New FAQs: * [4.2] What updates were made for the 05/02 release? * [5.6] Wait a minute, does that previous FAQ say to not answer their question just because it's already answered in the FAQ?!? * [15.11] How can I tell {if a key, which key} was pressed before the user presses the ENTER key? (inspired by a posting by Alan Didey) * [15.12] How can make it so keys pressed by users are not echoed on the screen? * [15.13] How can I move the cursor around on the screen? * [25.1] Can sizeof(char) be 2 on some machines? For example, what about double-byte characters? (inspired by Randy Sherman) * [25.2] What are the units of sizeof? (inspired by Randy Sherman) * [25.3] Whoa, but what about machines or compilers that support multibyte characters. Are you saying that a "character" and a char might be different?!? (inspired by Randy Sherman) * [25.4] But, but, but what about machines where a char has more than 8 bits? Surely you're not saying a C++ byte might have more than 8 bits, are you?!? (thanks to Randy Sherman) * [25.5] Okay, I could imagine a machine with 9-bit bytes. But surely not 16-bit bytes or 32-bit bytes, right? (thanks to Randy Sherman) * [25.6] I'm sooooo confused. Would you please go over the rules about bytes, chars, and characters one more time? (thanks to Randy Sherman) * [25.7] What is a "POD type"? * [25.8] When initializing non-static data members of built-in / intrinsic / primitive types, should I use the "initialization list" or assignment? * [25.9] When initializing static data members of built-in / intrinsic / primitive types, should I worry about the "static initialization order fiasco"? * [25.10] Can I define an operator overload that works with built-in / intrinsic / primitive types? * [25.11] When I delete an array of some built-in / intrinsic / primitive type, why can't I just say delete a instead of delete[] a? Changed FAQs: * [6.13] What are some "interview questions" I could ask that would let me know if candidates really know their stuff? (rewrote from scratch thanks to Robin) * [7.6] How can I prevent other programmers from violating encapsulation by seeing the private parts of my class? (minor rewording) * [11.14] Is there a way to force new to allocate memory from a specific memory area? (two typos ("myPool" vs. "pool") in the code were fixed thanks to Randy Sherman) * [31.3] How can I include a non-system C header file in my C++ code? (fixed a grammatical error in the first paragraph thanks to Randy Sherman) * [35.13] Is it possible to convert C++ to C? (added a URL for Cfront <http://www.unipress.com/toolkit/> and reworded the third bullet) ============================================================================== [4.3] What updates were made for the 04/02 release? New FAQs: * [4.3] What updates were made for the 04/02 release? * [11.14] Is there a way to force new to allocate memory from a specific memory area? (inspired by a conversation with Tuan Tran) * [26.13] Should I use "unusual" syntax? Changed FAQs: * [2.1] Where's the closest mirror site to access this document? (added URL to the mirror site in the Netherlands thanks to Almer Visser) * [13.10] Should I design my classes from the outside (interfaces first) or from the inside (data first)? (rewrote the rationale for hiding nodes as inspired by a discussion with Michael Lacher) * [26.12] Are there any other sources of coding standards? (added several new links and updated numerous changed URLs thanks to John Vorwald) * [35.5] Where can I get information about the C++ compiler from {Borland, IBM, Microsoft, Sun, etc.}? (updated URLs for Intel's and Watcom's C++ compilers, and added Open Watcom, thanks to Dave Symonds) ============================================================================== [4.4] What updates were made for the 03/02 release? Global changes: * Changed the HTML "anchor" scheme so it conforms to the standard <http://www.htmlhelp.com/reference/html40/special/a.html>. Thanks to Eric Anderson for pointing this out. New FAQs: * [4.4] What updates were made for the 03/02 release? * [6.13] What are some "interview questions" I could ask that would let me know if candidates really know their stuff? (thanks to inspiration from Shawn Panosian) * [33.11] Why can't I separate the definition of my templates class from it's declaration and put it inside a .cpp file? (thanks to Assaf Lavie) * [36.1] How can I generate HTML documentation for my classes? Does C++ have anything similar to javadoc? (thanks to Joe Linoff) Changed FAQs: * [3.1] Is there a C++ FAQ Book in addition to the C++ FAQ Lite? (changed the URL for book excerpts <http://cseng.aw.com/book/0,,0201309831,00.html> thanks to Chris Young) * [5.1] What does IMHO mean? (or IMO, IMNSHO, FWIW, OTOH, etc.)? (added OO) * [6.10] Is C++ backward compatible with ANSI/ISO C? (clarified the relationship between f() in C and f(...) in C++ thanks to Stefan Farfeleder) * [6.12] Where can I get a copy of the ANSI/ISO C++ standard? (swapped some mixed up links thanks to Randal Leistikow) * [8.7] What is a handle to an object? Is it a pointer? Is it a reference? Is it a pointer-to-a-pointer? What is it? (changed pointers-to-references into references-to-pointers thanks to Scott Douglass) * [13.1] What's the deal with operator overloading? (added comment about templates and intrinsic types thanks to Phil Hibbs) * [15.1] Why should I use <iostream> instead of the traditional <cstdio>? (corrected grammar of first bullet ("better type safety" ==> "more type-safe") thanks to Tristan Miller) * [15.14] Why can't I open a file in a different directory such as "..\test.dat"? (added an explanation as to why "/" is better than "\\" thanks to Chris Young) * [16.2] Can I free() pointers allocated with new? Can I delete pointers allocated with malloc()? (strengthened) * [18.10] What do I do if I want a const member function to make an "invisible" change to a data member? (added a caveat about this being a const Set* const thanks to Steve White) * [20.4] I have a heterogeneous list of objects, and my code needs to do class-specific things to the objects. Seems like this ought to use dynamic binding but can't figure it out. What should I do? (fixed typo in a typedef thanks to Salminen Kari; plus various clarifications throughout) * [20.6] What is a "virtual constructor"? (added parenthetical recommendation about slicing thanks to Jesse Jones) * [21.2] Derived* --> Base* works OK; why doesn't Derived** --> Base** work? (added a paragraph near the end about using a pointer cast thanks to Steve White) * [21.6] Is a Circle a kind-of an Ellipse? (reworded) * [21.7] Are there other options to the "Circle is/isnot kind-of Ellipse" dilemma? (added words allowing Circle to be a state of Ellipse rather than a class in itself thanks to Nicholas Leippe) * [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? (softened things up in two spots (thanks to Salminen Kari and Nicholas Leippe) and made it even more in-your-face in other spots (blame the author[1.2] for this second set of changes -- I'm the meanie)) * [26.7] What source-file-name convention is best? foo.cpp? foo.C? foo.cc? (rewrote/wordsmithed thanks to Michael Tiller) * [26.12] Are there any other sources of coding standards? (removed a dead link thanks to Phil Hibbs) * [27.7] What are some best-of-breed C++ programming-by-example guides? (added Musser's STL book thanks to Xavier Outhier from D2SET scientific and technology non profit association <http://www.d2set.org>) * [34.2] Where can I get a copy of "STL"? (removed dead link to Musser's STL site thanks to Xavier Outhier from D2SET scientific and technology non profit association <http://www.d2set.org>) * [34.4] Where can I get help on how to use STL? (removed dead link to Musser's STL site thanks to Xavier Outhier from D2SET scientific and technology non profit association <http://www.d2set.org>; added link to book section) * [34.9] Where can I get tons and tons of more information on C++ class libraries? (added the URL to www.mathtools.net/C++/ thanks to Ophir Herbst) * [35.1] Where can I download a free C++ compiler? (added Digital Mars to the list (thanks Walter!)) * [35.4] How can I decompile an executable program back into C++ source code? (added caveat at the end re legitimate reasons to decompile) * [35.5] Where can I get information about the C++ compiler from {Borland, IBM, Microsoft, Sun, etc.}? (removed Symantec C++ since Symantec's web site says it is "discontinued," thanks to Richard Gill; added an annotation that the Digital Mars compiler is free, thanks to Walter Bright; and added the URL to the Cygwin-compiled version of GCC, thanks to Wouter Demuynck) * [36.14] Why doesn't my floating-point comparison work? (added new book references thanks to Alan McKenney) * [37.2] Are there any pretty-printers that reformat C++ source code? (added "Source Styler for C++" thanks to Alison Boyce) ============================================================================== [4.5] What updates were made for the 08/01 release? New features: * You can now search the C++ FAQ[search-the-faq] (thanks to www.google.com). * The FAQ has now been translated into Chinese using the GB encoding[2.5] (typically used on the Chinese mainland). New FAQs: * [4.5] What updates were made for the 08/01 release? * [5.10] Should I post job advertisements and/or resumes on comp.lang.c++? (thanks to David Harmon and Brian B. Rodenborn) * [5.11] What if I really need a job; should I post my resume on comp.lang.c++? (thanks to David Harmon and Brian B. Rodenborn) * [5.12] What should I do to someone who posts something off-topic? * [5.13] What about spam? * [10.13] Why doesn't the construct-on-first-use idiom use a static object instead of a static pointer? * [10.15] Do I need to worry about the "static initialization order fiasco" for variables of built-in/intrinsic types? (thanks to Cyril Schmidt) * [20.4] I have a heterogeneous list of objects, and my code needs to do class-specific things to the objects. Seems like this ought to use dynamic binding but can't figure it out. What should I do? (based on an email discussion with Jeramie Hicks) * [23.7] How can I set up my class so it won't be inherited from? * [23.8] How can I set up my member function so it won't be overridden in a derived class? * [26.10] Why do people worry so much about pointer casts and/or reference casts? * [35.13] Is it possible to convert C++ to C? (thanks to J. Stephen Adamczyk and Greg Comeau) * [36.14] Why doesn't my floating-point comparison work? (thanks to Stan Brown) Changed FAQs: * [2.1] Where's the closest mirror site to access this document? (removed the Finland mirror site -- it wasn't being kept up-to-date) * [2.5] Where can I download a Chinese translation of the C++ FAQ Lite? (added the URL for the GB-encoded version thanks to Shen Min for the translation) * [10.6] Should my constructors use "initialization lists" or "assignment"? (reworded various things thanks to Stan Brown) * [10.7] Should you use the this pointer in the constructor? (wordsmithed thanks to Stan Brown) * [10.11] What's the "static initialization order fiasco"? (closed loophole wrt built-in/intrinsic types thanks to Cyril Schmidt) * [10.12] How do I prevent the "static initialization order fiasco"? (closed loophole wrt built-in/intrinsic types thanks to Cyril Schmidt) * [10.14] How do I prevent the "static initialization order fiasco" for my static data members? (closed loophole wrt built-in/intrinsic types thanks to Cyril Schmidt) * [10.17] What is the "Named Parameter Idiom"? (wordsmithed and added last paragraph with inspiration from Stan Brown) * [14.2] Do friends violate encapsulation? (added the last paragraph with inspiration from Stan Brown) * [14.4] What does it mean that "friendship isn't inherited, transitive, or reciprocal"? (wordsmithed ("nor" vs. "or") thanks to Herbert Gintis) * [15.15] How do I convert a value (a number, for example) to a std::string? (changed <stdio> to <cstdio> thanks to Stan Brown) * [15.16] How do I convert a std::string to a number? (changed <stdio> to <cstdio> thanks to Stan Brown) * [16.5] Do I need to check for NULL after p = new Fred()? (changed endl to std::endl) * [16.24] Can you absolutely prevent people from subverting the reference counting mechanism, and if so, should you? (wordsmithed thanks to Stan Brown) * [16.25] Can I use a garbage collector in C++? (added cross-references thanks to Stan Brown) * [16.26] What are the two kinds of garbage collectors for C++? (added a URL for Attardi and Flagella's CMM thanks to Markus Laker) * [19.7] How can I protect derived classes from breaking when I change the internal parts of the base class? (wordsmithed thanks to Stan Brown) * [20.6] What is a "virtual constructor"? (added the paragraph about MS VC++ 6.0's mishandling of Covariant Return Types; thanks to Karthik for pointing this out) * [27.4] Should I buy one book, or several? (wordsmithed thanks to Stan Brown) * [31.1] What do I need to know when mixing C and C++ code? (fixed a typo thanks to Kumaran Surrendra; added the paragraph on compiling everything, even C-style code, using a C++ compiler thanks to Gary Jenkins) * [34.2] Where can I get a copy of "STL"? (added comment about "<string>" thanks to Stan Brown) * [35.5] Where can I get information about the C++ compiler from {Borland, IBM, Microsoft, Sun, etc.}? (added URL for Digital Mars C++ <http://www.digitalmars.com/> thanks to Walter Bright) * [36.4] What should be done with macros that need to paste two tokens together? (removed ambivalence regarding second layer of indirection when using ## thanks to Joshua Fraser and Ronald Fischer) * [37.1] Is there a TeX or LaTeX macro that fixes the spacing on "C++"? (wordsmithed thanks to Stan Brown) ============================================================================== [4.6] What updates were made for the 04/01 release? Global changes: * Updated the opening page so it lists both the chain of recent changes as well as the table of recent changes. This improvement is thanks to a suggestion by John Kewley. Moved the main FAQ site to www.parashift.com/c++-faq-lite/. (This was unfortunately necessary due to a business issue involving AT&T and the previous web hosting company, Cerf-Net.) New FAQs: * [2.8] Where can I download a Russian translation of the C++ FAQ Lite? (thanks to Yaroslav Mironov) * [4.6] What updates were made for the 04/01 release? * [8.4] What does object.method1().method2() mean? (thanks to Robert Cullen) * [8.7] What is a handle to an object? Is it a pointer? Is it a reference? Is it a pointer-to-a-pointer? What is it? * [10.17] What is the "Named Parameter Idiom"? * [16.18] What's another way to build a Matrix template? (thanks to Jesper Rasmussen) * [16.24] Can you absolutely prevent people from subverting the reference counting mechanism, and if so, should you? * [23.1] Is it okay for a non-virtual function of the base class to call a virtual function? * [23.2] That last FAQ confuses me. Is it a different strategy from the other ways to use virtual functions? What's going on? * [27.7] What are some best-of-breed C++ programming-by-example guides? * [33.8] How do I explicitly select which version of a function template should get called? (with help from Perry Rapp) Changed FAQs: * [5.2] How do I get other people to do my homework problem for me? (added stuff about the evils of asking others to do your homework for you via email) * [6.12] Where can I get a copy of the ANSI/ISO C++ standard? (total rewrite; changed several URLs thanks to Brian K. Hamon and Garen Parham) * [9.7] Are inline functions guaranteed to make your performance better? (explained "code bloat" and also added lots of if's, and's and but's) * [10.6] Should my constructors use "initialization lists" or "assignment"? (rewrote) * [10.7] Should you use the this pointer in the constructor? (rewrote because of a suggestion from Perry Rapp) * [10.9] Why can't I initialize my static member data in my constructor's initialization list? (added a "," in the initialization list thanks to Yaroslav Mironov) * [14.2] Do friends violate encapsulation? (made a bit more emphatic) * [14.4] What does it mean that "friendship isn't inherited, transitive, or reciprocal"? (added the "not reciprocal" item thanks to Karel Roose) * [15.7] But shouldn't I always use a printOn() method rather than a friend function? (fixed a bug thanks to Richard Hector) * [16.16] But the previous FAQ's code is SOOOO tricky and error prone! Isn't there a simpler way? (fixed the Star Trek movie number thanks to Chris Sheppard) * [16.16] But the previous FAQ's code is SOOOO tricky and error prone! Isn't there a simpler way? (wordsmithed last paragraph at the suggestion of prapp) * [16.21] How do I do simple reference counting? (moved definition of Fred::create() methods below the definition of class FredPtr) * [16.26] What are the two kinds of garbage collectors for C++? (added a URL for Bartlett's collector thanks to Abhishek) * [17.2] How can I handle a constructor that fails? (fixed typo ("its" vs. "it's") thanks to Wes Bemont) * [24.2] How are "private inheritance" and "composition" similar? (changed the syntax to using Engine::start; and added the sixth distinction thanks to Stan Brown; added the third similarity; added "aggregation" as another synonym; wordsmithed various parts) * [26.1] What are some good C++ coding standards? (fixed typo changing "where" to "were" thanks to Robert Marshall) * [26.11] Which is better: identifier names that_look_like_this or identifier names thatLookLikeThis? (clarified the last paragraph) * [26.12] Are there any other sources of coding standards? (added a new URL thanks to Christopher Lott <chris "at" lott.com>; added www.arcticlabs.com/codingstandards/ thanks to Richard) * [27.4] Should I buy one book, or several? (rewrote; added the "programming by example" category) * [30.2] What is "virtual data," and how-can / why-would I use it in C++? (fixed the sentence just before Pros & Cons list (changed StretchableArray to StretchableStack) thanks to Harri Klapuri) * [31.2] How can I include a standard C header file in my C++ code? (added the whole section on "compiling C code with a C++ compiler," with inspiration thanks to Sebastian Kapfer) * [32.6] How do I create and use an array of pointers to member functions? (removed the array size from the declaration of array a, that way there's one less thing to change if someone ever adds another function-pointer to the array thanks to Serge Ansay) * [33.1] Why should I use container classes rather than simple arrays? (clarified "local" vs. "non-static local" thanks to Garen Parham) * [35.1] Where can I download a free C++ compiler? (changed to a different site since the old URL was dead thanks to Victor R. Volkman) * [35.5] Where can I get information about the C++ compiler from {Borland, IBM, Microsoft, Sun, etc.}? (fixed "Semantic" to "Symantec" and "Gary Comeau" to "Greg Comeau" thanks to Scott Tringali; fixed the URL to SGI's compiler thanks to Toon Knapen) * [35.11] Is there a yacc-able C++ grammar? (rewrote; added a new grammar/lexer plus a new URL for the old grammar/lexer thanks to Ed Willink) * [37.1] Is there a TeX or LaTeX macro that fixes the spacing on "C++"? (added a new LaTeX macro thanks to Bob Kline; rewrote) * [37.2] Are there any pretty-printers that reformat C++ source code? (fixed the URL for Artistic Style <http://astyle.sourceforge.net/> thanks to Claus Dahl; added A2PS <http://www.infres.enst.fr/~demaille/a2ps/> thanks to Clark Dorman) ============================================================================== [4.7] What updates were made for the 07/00 release? Global changes: * Moved the main FAQ site to www.parashift.com/c++-faq-lite/. (This was unfortunately necessary due to a business issue involving AT&T and the previous web hosting company, Cerf-Net.) New FAQs: * [4.7] What updates were made for the 07/00 release? * [11.13] Should my destructor throw an exception when it detects a problem? * [15.7] But shouldn't I always use a printOn() method rather than a friend function? * [15.15] How do I convert a value (a number, for example) to a std::string? (thanks to Rob Stewart) * [15.16] How do I convert a std::string to a number? (thanks to Rob Stewart) * [16.25] Can I use a garbage collector in C++? (thanks to Hans Boehm) * [16.26] What are the two kinds of garbage collectors for C++? (thanks to Hans Boehm) * [16.27] Where can I get more info on garbage collectors for C++? * [17.1] What are some ways try / catch / throw can improve software quality? * [17.3] How can I handle a destructor that fails? * [21.9] Perhaps Ellipse should inherit from Circle then? * [33.1] Why should I use container classes rather than simple arrays? (with help from Stan Brown) Changed FAQs: * [2.5] Where can I download a Chinese translation of the C++ FAQ Lite? (updated the URL) * [3.1] Is there a C++ FAQ Book in addition to the C++ FAQ Lite? (added BookPool.com <http://www.bookpool.com/.x/oboisf4qor/sm/0201309831> and AllDirect.com <http://www.alldirect.com/book.asp?isbn=0201309831> thanks to Stan Brown, plus reorganized) * [3.2] Is there a big difference between C++ FAQ Lite and C++ FAQ Book? (changed 'much' to 'many' thanks to Stan Brown) * [6.5] Who uses C++? (rewrote) * [6.8] Are virtual functions (dynamic binding) central to OO/C++? (inserted "the" before "difference" thanks to Stan Brown and reworded references to STL) * [6.11] Is C++ standardized? (changed "has been finalized" to "was finalized" thanks to Stan Brown) * [6.12] Where can I get a copy of the ANSI/ISO C++ standard? (added URLs to free copies of CD2) * [9.3] Why should I use inline functions? Why not just use 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.8] How do I create a subscript operator for a Matrix class? (changed so it uses new-style headers and the std:: syntax) * [13.10] 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.3] How does that funky while (std::cin >> foo) syntax work? (changed so it uses new-style headers and the std:: syntax) * [15.4] Why does my input seem to process past the end of file? (changed so it uses new-style headers and the std:: syntax) * [15.5] Why is my program ignoring my input request after the first iteration? (changed so it uses new-style headers and the std:: syntax) * [15.6] How can I provide printing for my class Fred? (changed so it uses new-style headers and the std:: syntax) * [15.8] How can I provide input for my class Fred? (changed so it uses new-style headers and the std:: syntax) * [15.9] How can I provide printing for an entire hierarchy of classes? (changed so it uses new-style headers and the std:: syntax) * [15.10] How can I "reopen" std::cin and std::cout in binary mode under DOS and/or OS/2? (changed so it uses new-style headers and the std:: syntax) * [15.14] 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.5] Do I need to check for NULL after p = new Fred()? (changed so it uses new-style headers and the std:: syntax) * [16.6] 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.13] 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.15] 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.16] But the previous FAQ's code is SOOOO tricky and error prone! Isn't there a simpler way? (clarified the last paragraph) * [16.17] But the above Matrix class is specific to Fred! Isn't there a way to make it generic? (rewrote) * [16.19] 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.22] How do I provide reference counting with copy-on-write semantics? (rewrote the first paragraph for clarity thanks to Fabrice Clerc) * [16.23] 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.5] 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.9] What is a "const member function"? (removed a spurious ")" thanks to Stan Brown) * [18.12] Why does the compiler allow me to change an int after I've pointed at it with a const int*? (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") * [26.4] What's the difference between <xxx> and <xxx.h> headers? (changed <xyz.h> to <xxx.h> and wordsmithed thanks to Stan Brown) * [26.5] Is the ?: operator evil since it can be used to create unreadable code? (changed so it uses new-style headers and the std:: syntax) * [26.9] Are there any lint-like guidelines for C++? (changed so it uses new-style headers and the std:: syntax) * [26.11] 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) * [26.12] Are there any other sources of coding standards? (fixed some URLs thanks to James S. Adelman and Stan Brown) * [29.4] How do you use inheritance in C++, and is that different from Smalltalk? (renamed "subclass" to "derived class") * [29.5] What are the practical consequences of differences in Smalltalk/C++ inheritance? (renamed "subclass" to "derived class") * [30.3] What's the difference between virtual data and dynamic data? (renamed "subclass" to "derived class") * [30.8] Does the poor performance of reference semantics mean I should pass-by-value? (renamed "subclass" to "derived class") * [33.2] How can I make a perl-like associative array in C++? (changed so it uses new-style headers and the std:: syntax) * [33.4] 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) * [33.6] What's the syntax / semantics for a "class template"? (changed so it uses new-style headers and the std:: syntax) * [33.7] What's the syntax / semantics for a "function template"? (changed so it uses new-style headers and the std:: syntax) * [34.1] What is the "STL"? (changed so it uses new-style headers and the std:: syntax) * [34.2] Where can I get a copy of "STL"? (added URLs for the SGI implementation <http://www.sgi.com/Technology/STL/> and STLport <http://www.stlport.org> thanks to Stan Brown) * [34.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) * [35.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++ <http://gcc.gnu.org/> thanks to Martin Honnen) * [36.2] 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)) * [36.3] What should be done with macros that have multiple lines? (changed "if (1)..." to "if (true)..." and "do...while (0)" to "do...while (false)") * [36.6] 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) * [36.9] Why is floating point so inaccurate? Why doesn't this print 0.43? (changed so it uses new-style headers and the std:: syntax) * [36.13] Why can't I put a forward-declared class in a std::vector<>? (changed so it uses new-style headers and the std:: syntax) * [37.2] Are there any pretty-printers that reformat C++ source code? (added HPS Beauty) * [37.5] Why does my DOS C++ program says "Sorry: floating point code not linked"? (added a cross reference and updated to new header syntax) ============================================================================== [4.8] What updates were made for the 03/00 release? New FAQs: * [4.8] What updates were made for the 03/00 release? * [36.2] What should be done with macros that contain if? * [36.3] What should be done with macros that have multiple lines? * [36.4] What should be done with macros that need to paste two tokens together? Changed FAQs: * [2.7] Where can I download a Portuguese translation of the C++ FAQ Lite? (updated the URL for the Portuguese translation of the FAQ thanks to Ricardo F. de Oliveira) * [3.1] Is there a C++ FAQ Book in addition to the C++ FAQ Lite? (rewrote) * [3.2] Is there a big difference between C++ FAQ Lite and C++ FAQ Book? (rewrote) * [6.12] Where can I get a copy of the ANSI/ISO C++ standard? (changed the URL for the electronic copy of the Standard thanks to Wolfgang Haefelinger) * [9.3] Why should I use inline functions? Why not just use plain old #define macros? (added cross references to other evilness of macros) * [11.8] What if I can't wrap the local in an artificial block? (added the note about constructors at the end) * [13.10] Should I design my classes from the outside (interfaces first) or from the inside (data first)? (added friend relationship between LinkedListIterator and LinkedList thanks to Mónica García García; reworded "In the case of OO software..." sentence thanks to Fabrice Clerc) * [18.10] What do I do if I want a const member function to make an "invisible" change to a data member? (added a warning against use of const_cast on const objects thanks to TiTi) * [20.6] What is a "virtual constructor"? (added the paragraph on Covariant Return Types) * [29.3] Which is a better fit for C++: "static typing" or "dynamic typing"? (added cross references to evilness of macros) * [31.4] How can I modify my own C header files so it's easier to #include them in C++ code? (added the "macros are sometimes useful" paragraph at the end) * [32.1] Is the type of "pointer-to-member-function" different from "pointer-to-function"? (changed another "It's" to "Its" thanks to Chris Young) * [32.5] How can I avoid syntax errors when calling a member function using a pointer-to-member-function? (added the "macros are sometimes useful" paragraph at the end) * [32.6] How do I create and use an array of pointers to member functions? (added the "macros are sometimes useful" paragraph at the end) ============================================================================== [4.9] What updates were made for the 01/00 release? New FAQs: * [4.9] What updates were made for the 01/00 release? * [10.7] Should you use the this pointer in the constructor? (with the help of Jim Hyslop) * [26.4] What's the difference between <xxx> and <xxx.h> headers? (thanks to Stan Brown) Changed FAQs: * [2.1] Where's the closest mirror site to access this document? (changed the rationale for choosing a close site thanks to Stan Brown) * [2.4] Why is the download via email? Why not via ftp? (added caveat that out-of-date reminders aren't implemented yet thanks to Stan Brown) * [5.1] What does IMHO mean? (or IMO, IMNSHO, FWIW, OTOH, etc.)? (added IMAO thanks to Charles R Martin) * [5.14] How do I get the FAQs for a particular newsgroup? (added www.faqs.org thanks to Dan Kegel) * [6.8] Are virtual functions (dynamic binding) central to OO/C++? (reworded the second paragraph thanks to Stan Brown) * [6.11] Is C++ standardized? (changed "American National Standards Organization" to "American National Standards Institute" thanks to Mark Jones; also reworded first paragraph thanks to Stan Brown) * [12.1] What is "self assignment"? (changed "knowning" to "knowing" thanks to Stan Brown) * [12.3] OK, OK, already; I'll handle self-assignment. How do I do it? (reworded the last paragraph thanks to Stan Brown) * [13.5] What operators can/cannot be overloaded? (got rid of #if/#else/#endif by splitting the example thanks to Stan Brown) * [15.14] Why can't I open a file in a different directory such as "..\test.dat"? (added an explanation that the library routines treat "/" and "\" interchangeably thanks to Stan Brown) * [18.13] Does "const Fred* p" mean that *p can't change? (added an indication that there might be other non-const ways to get at the object thanks to Stan Brown) * [20.2] How can C++ achieve dynamic binding yet also static typing? (added the definition of polymorphism thanks to Kemberli Jennings) * [22.5] How do you define a copy constructor or assignment operator for a class that contains a pointer to a (abstract) base class? (fixed Circle and Square so they inherit from Shape thanks to Paul Campbell) * [32.1] Is the type of "pointer-to-member-function" different from "pointer-to-function"? (changed "It's type is..." to "Its type is..." thanks to Graham Borland) * [33.4] How can I insert/access/change elements from a linked list/hashtable/etc? (reworded first 4 paragraphs thanks to Stan Brown) * [35.2] Where can I get more information on using MFC and Visual C++? (updated the URL thanks to Katy Mulvey; changed the maintainer's name thanks to AllanW) * [35.5] Where can I get information about the C++ compiler from {Borland, IBM, Microsoft, Sun, etc.}? (changed the URL for Watcom C++ thanks to Stephen Howe; added Comeau C++ thanks to Greg Comeau) ============================================================================== [4.10] What updates were made for the 10/99 release? New FAQs: * [2.6] Where can I download a French translation of the C++ FAQ Lite? * [4.10] What updates were made for the 10/99 release? * [13.9] Why shouldn't my Matrix class's interface look like an array-of-array? * [34.1] What is the "STL"? * [36.10] How can I create two classes that both know about each other? (thanks to Steve Horne) * [36.11] What special considerations are needed when forward declarations are used with member objects? (thanks to Steve Horne) * [36.12] What special considerations are needed when forward declarations are used with inline functions? (thanks to Steve Horne) * [36.13] Why can't I put a forward-declared class in a std::vector<>? (thanks to Steve Horne) Changed FAQs: * [6.11] Is C++ standardized? (changed "International Standards Organization" to "International Organization for Standardization" thanks to savvysoft2@aol.com) * [7.1] What is a class? (cleaned up wording so no one thinks int is a class thanks to Ron Natalie) * [8.1] What is a reference? (added return type to main()) * [8.2] What happens if you assign to a reference? (inserted "state of the" to avoid ambiguity thanks to Donna) * [8.3] What happens if you return a reference? (added return type to main()) * [10.5] Which constructor gets called when I create an array of Fred objects? (added return type to main(), plus added stuff about "explicit initialization of arrays" thanks to Keller Beyer) * [10.8] What is the "Named Constructor Idiom"? (added return type to main()) * [12.1] What is "self assignment"? (added return type to main()) * [13.4] But operator overloading makes my class look ugly; isn't it supposed to make my code clearer? (added return type to main()) * [13.5] What operators can/cannot be overloaded? (added return type to main()) * [13.6] Can I overload operator== so it lets me compare two char[] using a string comparison? (replaced "class type" with "user-defined type" in first paragraph thanks to Daryle Walker) * [13.8] How do I create a subscript operator for a Matrix class? (added return type to main(); added parameters to the instantiation of m in main() thanks to Boris Pulatov) * [13.10] Should I design my classes from the outside (interfaces first) or from the inside (data first)? (added an admonition to not "roll your own" container classes) * [15.2] Why does my program go into an infinite loop when someone enters an invalid input character? (added return type to main()) * [15.4] Why does my input seem to process past the end of file? (strengthened the message with another example) * [15.6] How can I provide printing for my class Fred? (added return type to main()) * [15.8] How can I provide input for my class Fred? (added return type to main()) * [15.14] Why can't I open a file in a different directory such as "..\test.dat"? (added return type to main()) * [16.6] How can I convince my (older) compiler to automatically check new to see if it returns NULL? (added return type to main()) * [16.20] How can I force objects of my class to always be created via new rather than as locals or global/static objects? (added return type to main()) * [18.12] Why does the compiler allow me to change an int after I've pointed at it with a const int*? (added return type to main()) * [18.13] Does "const Fred* p" mean that *p can't change? (added return type to main()) * [21.2] Derived* --> Base* works OK; why doesn't Derived** --> Base** work? (added return type to main(); added methods openGasCap() and fireNuclearMissle() -- makes the example more exciting) * [21.4] Is an array of Derived a kind-of array of Base? (added return type to main()) * [24.4] Should I pointer-cast from a private derived class to its base class? (changed PrivateDer to PrivatelyDer in last paragraph) * [24.6] What are the access rules with private and protected inheritance? (rewritten with the using syntax; thanks to Stephen Vance) * [31.2] How can I include a standard C header file in my C++ code? (added return type to main()) * [31.3] How can I include a non-system C header file in my C++ code? (added return type to main()) * [31.4] How can I modify my own C header files so it's easier to #include them in C++ code? (added return type to main()) * [31.5] How can I call a non-system C function f(int,char,float) from my C++ code? (added return type to main()) * [32.2] How do I pass a pointer to member function to a signal handler, X event callback, etc? (added return type to main()) * [33.2] How can I make a perl-like associative array in C++? (added return type to main()) * [33.6] What's the syntax / semantics for a "class template"? (added return type to main()) * [33.7] What's the syntax / semantics for a "function template"? (added return type to main()) * [35.1] Where can I download a free C++ compiler? (fixed the URL) * [35.5] Where can I get information about the C++ compiler from {Borland, IBM, Microsoft, Sun, etc.}? (added Edison Design Group C++ thanks to Matt Page) * [36.9] Why is floating point so inaccurate? Why doesn't this print 0.43? (added return type to main()) * [37.2] Are there any pretty-printers that reformat C++ source code? (added Artistic Style thanks to Philipp Berndt, fixed the URL for C++2LaTeX thanks to Vinay Kumar Nallamothu, fixed the URL for C-Clearly thanks to Bill Robertson; fixed the plaintext version (the "grind" definition didn't show up there) thanks to Nimrod Zimerman) ============================================================================== [4.11] What updates were made for the 07/99 release? New FAQs: * [4.11] What updates were made for the 07/99 release? * [35.1] Where can I download a free C++ compiler? Changed FAQs: * [1.6] C++-FAQ-Lite != C++-FAQ-Book (updated due to the Second Edition of the book) * [2.1] Where's the closest mirror site to access this document? (added Ireland mirror site: snet.wit.ie/GreenSpirit/c++-faq-lite) * [2.2] How can I get a Copy of all the HTML files of C++ FAQ Lite so I can read them Off-Line? (added "Windows 98" to last paragraph) * [3.1] Is there a C++ FAQ Book in addition to the C++ FAQ Lite? (updated due to the Second Edition of the book) * [6.5] Who uses C++? (corrected the growth rate) * [6.8] Are virtual functions (dynamic binding) central to OO/C++? (added STL and generic programming) * [6.12] Where can I get a copy of the ANSI/ISO C++ standard? (added new ways to get a copy via the web) * [12.3] OK, OK, already; I'll handle self-assignment. How do I do it? (tightened the wording of the last paragraph thanks to Andy Glew) * [15.3] How does that funky while (std::cin >> foo) syntax work? (corrected a serious bug: changed operator bool() to operator void*(); thanks to Rajinikanth Sivalingam) * [16.23] How do I provide reference counting with copy-on-write semantics for a hierarchy of classes? (fixed a bug by making Fred a friend of Fred::Data) * [18.9] What is a "const member function"? (changed "const pointer" to "pointer-to-const" thanks to Saieb Khalil) * [20.5] When should my destructor be virtual? (changed "explicit destructor" to "explicitly defined destructor" to avoid confusion with the explicit keyword used with constructors) * [23.4] Should a derived class replace ("override") a non-virtual function from a base class? (reworded first full paragraph) * [26.12] Are there any other sources of coding standards? (removed the URL for the anti-guide (thanks to Bill Seymour for letting me know that the anti-guide disappeared)) * [27.5] What are some best-of-breed C++ morality guides? (updated info on C++ FAQs book because of its Second Edition) * [27.6] What are some best-of-breed C++ legality guides? (fixed the ISBN for Bjarne Stroustrup's book) * [30.1] What is value and/or reference semantics, and which is best in C++? (wordsmithed changes thanks to Lance Ware) * [33.4] How can I insert/access/change elements from a linked list/hashtable/etc? (reworded item #3 thanks to John Millaway) * [34.3] How can I find a Fred object in an STL container of Fred* such as std::vector<Fred*>? (fixed a typo in the code thanks to Scott Maxwell and Bill Sloan) * [35.4] How can I decompile an executable program back into C++ source code? (wordsmithed changes thanks to Lance Ware) * [35.5] Where can I get information about the C++ compiler from {Borland, IBM, Microsoft, Sun, etc.}? (corrected the URL for KAI C++ and added Rational APEX C/C++ thanks to Kevin Broadey; corrected the URL for Borland C++ FAQ thanks to Kent Reisdorph and Michael J. Reeves) * [36.6] What are the C++ scoping rules for for loops? (wordsmithed thanks to Lance Ware) ============================================================================== [4.12] What updates were made for the 06/98 release? New FAQs: * [4.12] What updates were made for the 06/98 release? * [10.16] How can I handle a constructor that fails? Changed FAQs: * [34.9] Where can I get tons and tons of more information on C++ class libraries? (fixed the URL) ============================================================================== [4.13] What updates were made for the 05/98 release? Global changes: * Removed the grey background color on the HTML version. It now displays in the Web Browser's own preferences. New FAQs: * [1.5] Trademarks * [2.4] Why is the download via email? Why not via ftp? * [2.7] Where can I download a Portuguese translation of the C++ FAQ Lite? * [4.13] What updates were made for the 05/98 release? * [10.6] Should my constructors use "initialization lists" or "assignment"? * [35.2] Where can I get more information on using MFC and Visual C++? Changed 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? (made it clearer why there is no FTP or HTTP address for downloading the FAQ) * [2.3] How can I get a Copy of all the "plaintext" files of C++ FAQ Lite so I can read them Off-Line? (made it clearer why there is no FTP or HTTP address for downloading the FAQ) * [6.11] Is C++ standardized? (rewrote now that the standard is here) * [6.12] Where can I get a copy of the ANSI/ISO C++ standard? (rewrote now that the standard is here) * [16.17] But the above Matrix class is specific to Fred! Isn't there a way to make it generic? (fixed Matrix's ctor thanks to Dhavide Aruliah) * [16.22] How do I provide reference counting with copy-on-write semantics? (fixed Fred's default ctor thanks to Scott Harris) * [34.3] How can I find a Fred object in an STL container of Fred* such as std::vector<Fred*>? (changed operator==() to operator()() thanks to Ali Tajeldin) * [34.4] Where can I get help on how to use STL? (added the URL for the STL FAQ) * [35.5] Where can I get information about the C++ compiler from {Borland, IBM, Microsoft, Sun, etc.}? (corrected the URL for Borland C++ & HP C++; added GNU C++, Intel Reference C++, KAI C++, and Portland Group C++) * [37.2] Are there any pretty-printers that reformat C++ source code? (added a URL for "GNU indent") ============================================================================== [4.14] What updates were made for the 09/97 release? New FAQs: * [4.14] What updates were made for the 09/97 release? * [10.11] What's the "static initialization order fiasco"? * [10.12] How do I prevent the "static initialization order fiasco"? * [10.14] How do I prevent the "static initialization order fiasco" for my static data members? * [16.17] But the above Matrix class is specific to Fred! Isn't there a way to make it generic? Changed FAQs: * [1.3] Copying Permissions (clarified) * [5.1] What does IMHO mean? (or IMO, IMNSHO, FWIW, OTOH, etc.)? (added silly acronym-laden comment at the bottom (adapted from e-mail from Erik Corry) * [16.16] But the previous FAQ's code is SOOOO tricky and error prone! Isn't there a simpler way? (fixed some inconsistencies between FredMatrix and Matrix thanks to Jeff Baker) * [16.21] How do I do simple reference counting? (fixed FredPtr's constructor thanks to Chichiang Wan) * [23.5] What's the meaning of, Warning: Derived::f(float) hides Base::f(int)? (rewritten with the using syntax; thanks to Matt Seitz) * [35.5] Where can I get information about the C++ compiler from {Borland, IBM, Microsoft, Sun, etc.}? (corrected the URL for Symantec C++ <http://www.symantec.com/scpp/index_product.html> thanks to Michel Joly de Lotbiniere and added the URL for HP C++ thanks to David Green) * [35.5] Where can I get information about the C++ compiler from {Borland, IBM, Microsoft, Sun, etc.}? (corrected the URL for Microsoft Visual C++ thanks to Leila Rannanjarvi, and added the URL for Sun C++ thanks to Aryan Mirsepassi) * [37.2] Are there any pretty-printers that reformat C++ source code? (added information about tgrind) ============================================================================== [4.15] What updates were made for the 01/97 release? 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.15] 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 (std::cin >> foo) syntax work? * [16.16] But the previous FAQ's code is SOOOO tricky and error prone! Isn't there a simpler way? * [26.5] 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.8] 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.3] 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) * [31.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) * [35.5] Where can I get information about the C++ compiler from {Borland, IBM, Microsoft, Sun, etc.}? (added HP C++) * [37.4] Where can I get OS-specific questions answered (e.g., BC++, DOS, Windows, etc)? (added Borland C++ URLs thanks to Simon Edlund) ============================================================================== [4.16] What updates were made for the 11/96 release? 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.16] 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? * [35.3] How do I display text in the status bar using MFC? (with the help of Paul Ganney) Changed FAQs: * [8.5] 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) * [26.12] Are there any other sources of coding standards? (rewrote and added more URLs) * [35.9] 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.17] What updates were made for the 10/96 release? New FAQs: * [4.17] What updates were made for the 10/96 release? Changed FAQs: * [5.9] 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) * [26.12] Are there any other sources of coding standards? (added URLs) * [35.5] Where can I get information about the C++ compiler from {Borland, IBM, Microsoft, Sun, etc.}? (added URL for Metrowerks and Watcom compilers) ============================================================================== [4.18] What updates were made for the 09/96 release? New FAQs: * [4.18] 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 other people 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) * [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? * [26.12] Are there any other sources of coding standards? * [35.4] How can I decompile an executable program back into C++ source code? (with the help of Phil Staite) Changed FAQs: * [8.5] 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.20] 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.22] How do I provide reference counting with copy-on-write semantics? (added links to the self assignment[12.1] discussion) * [16.23] 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.4] How should I handle resources if my constructors may throw exceptions? (added cross-references for reference-counted[16.21] 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) * [34.4] Where can I get help on how to use STL? (fixed the URL for Kenny Zalewski's STL guide) * [35.5] Where can I get information about the C++ compiler from {Borland, IBM, Microsoft, Sun, etc.}? (added URLs for Silicon Graphics and Symantec compilers) * [37.2] Are there any pretty-printers that reformat C++ source code? (added a URL for "V Communications") ============================================================================== [4.19] 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.19]" - The new look-and-feel "looks like this[4.19]" * Added section [12] Assignment operators * Added section [27] Learning OO/C++ New FAQs: * [4.19] 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.14] Why can't I open a file in a different directory such as "..\test.dat"? * [27.1] What is mentoring? * [27.2] Should I learn C before I learn OO/C++? * [27.3] Should I learn Smalltalk before I learn OO/C++? * [27.4] Should I buy one book, or several? * [27.5] What are some best-of-breed C++ morality guides? * [27.6] What are some best-of-breed C++ legality guides? * [27.8] Are there other OO books that are relevant to OO/C++? * [35.5] Where can I get information about the C++ compiler from {Borland, IBM, Microsoft, 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_") * [26.9] Are there any lint-like guidelines for C++? (added links to the self assignment[12.1] discussion) * [27.6] What are some best-of-breed C++ legality guides? (fixed the ISBN for Stan Lippman's book) * [29.1] What's the difference between C++ and Smalltalk? (rewritten) * [34.5] How can you tell if you have a dynamically typed C++ class library? (moved from the section on Smalltalk[29]) * [34.6] What is the NIHCL? Where can I get it? (moved from the section on Smalltalk[29]) * [34.9] Where can I get tons and tons of more information on C++ class libraries? (updated the URL) * [36.5] Why can't the compiler find my header file in #include "c:\test.hpp" ? (updated to refer to [15.14]) ============================================================================== [4.20] 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 [31] How to mix C and C++ New FAQs: * [4.20] 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.7] 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.8] What is the "Named Constructor Idiom"? * [10.9] 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.10] Should I design my classes from the outside (interfaces first) or from the inside (data first)? * [15.8] 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.21] How do I do simple reference counting? * [16.22] How do I provide reference counting with copy-on-write semantics? * [16.23] How do I provide reference counting with copy-on-write semantics for a hierarchy of classes? * [17.5] 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.6] What does it mean that the "virtual table" is an unresolved external? * [26.11] Which is better: identifier names that_look_like_this or identifier names thatLookLikeThis? (with the help of James Robinson) * [31.1] What do I need to know when mixing C and C++ code? * [32.5] How can I avoid syntax errors when calling a member function using a pointer-to-member-function? * [33.2] How can I make a perl-like associative array in C++? * [34.3] How can I find a Fred object in an STL container of Fred* such as std::vector<Fred*>? * [34.9] Where can I get tons and tons of more information on C++ class libraries? * [35.7] How do compilers use "over-allocation" to remember the number of elements in an allocated array? * [35.8] How do compilers use an "associative array" to remember the number of elements in an allocated array? * [36.5] Why can't the compiler find my header file in #include "c:\test.hpp" ? * [36.6] What are the C++ 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.8] 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.10] 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.9] How can I provide printing for an entire hierarchy of classes? (moved from the section on Abstraction[22]) * [16.20] 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.8]) * [31.2] How can I include a standard C header file in my C++ code? (rewritten) * [31.3] How can I include a non-system C header file in my C++ code? (rewritten) * [31.4] How can I modify my own C header files so it's easier to #include them in C++ code? (rewritten) * [35.11] Is there a yacc-able C++ grammar? (updated the URL for the yacc-able C++ grammar) * [37.2] Are there any pretty-printers that reformat C++ source code? (added "C-Clearly" and GNU indent to the list of pretty-printers) ============================================================================== [4.21] What updates were made for the 06/96 release? New FAQs: * [4.21] What updates were made for the 06/96 release? * [10.2] Is there any difference between List x; and List x();? * [36.9] Why is floating point so inaccurate? Why doesn't this print 0.43? (with the help of Phil Staite) Changed FAQs: * [2.1] Where's the closest mirror site to access this document? (added Finland mirror site: www.utu.fi/~sisasa/oasis/cppfaq/) * [3.1] Is there a C++ FAQ Book in addition to the C++ FAQ Lite? (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.5] 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) * [30.4] Should I normally use pointers to freestore allocated objects for my data members, or should I use "composition"? (reworded) * [31.8] How can I pass an object of a C++ class to/from a C function? (fixed a bug in the code) * [33.5] What's the idea behind templates? (reworded) * [33.6] What's the syntax / semantics for a "class template"? (reworded) * [37.1] Is there a TeX or LaTeX macro that fixes the spacing on "C++"? (added a new LaTeX macro) * [37.2] Are there any pretty-printers that reformat C++ source code? (fixed URL of C++2LaTeX) ============================================================================== [4.22] 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.23] What updates were made for the 04/96 release? New FAQs: * [4.23] What updates were made for the 04/96 release? * [31.2] How can I include a standard C header file in my C++ code? * [31.3] How can I include a non-system C header file in my C++ code? * [31.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: 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.24] What updates were made for the 03/96 release? New FAQs: * [4.24] 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?) * [33.3] How can I build a <favorite container> of objects of different types? (with the help of Phil Staite) 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 ANSI/ISO C++ standard? (fixed the URL for the ANSI/ISO C++ Committee Draft) * [15.1] Why should I use <iostream> instead of the traditional <cstdio>? (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) * [26.1] What are some good C++ coding standards? (reworded) * [26.2] Are coding standards necessary? Are they sufficient? (reworded) * [26.3] Should our organization determine coding standards from our C experience? (reworded) * [26.9] Are there any lint-like guidelines for C++? (reworded) * [29.3] Which is a better fit for C++: "static typing" or "dynamic typing"? (updated info on dynamic_cast and typeid()) * [37.2] Are there any pretty-printers that reformat C++ source code? (fixed URL of C++2LaTeX) ============================================================================== [4.25] What updates were made for the 09/95 release? New FAQs: * [4.25] What updates were made for the 09/95 release? * [15.10] How can I "reopen" std::cin and std::cout in binary mode under DOS and/or OS/2? * [34.4] Where can I get help on how to use STL? * [34.7] Where can I ftp the code that accompanies "Numerical Recipes"? * [34.8] Why is my executable so large? Changed FAQs: * [6.12] Where can I get a copy of the ANSI/ISO C++ 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) * [34.2] Where can I get a copy of "STL"? (reworded) ============================================================================== [4.26] What updates were made for the 06/95 release? New FAQs: * [4.26] 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) * [32.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 ANSI/ISO C++ standard? (fixed the US-Mail access for the ANSI/ISO C++ Committee Draft) * [16.20] How can I force objects of my class to always be created via new rather than as locals or global/static objects? (rewritten) ============================================================================== [4.27] What updates were made for the 04/95 release? New FAQs: * [4.27] What updates were made for the 04/95 release? * [37.4] Where can I get OS-specific questions answered (e.g., BC++, DOS, Windows, etc)? Changed FAQs: * [34.6] What is the NIHCL? Where can I get it? (fixed the FTP address) ============================================================================== [4.28] What updates were made for the 03/95 release? New FAQs: * [4.28] 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: * [37.3] Is there a C++-mode for GNU emacs? If so, where can I get it? (updated the information on cc-mode.el) ============================================================================== [4.29] What updates were made for the 01/95 release? New FAQs: * [2.5] Where can I download a Chinese translation of the C++ FAQ Lite? * [4.29] What updates were made for the 01/95 release? ============================================================================== [4.30] What updates were made for the 12/94 release? New FAQs: * [4.30] What updates were made for the 12/94 release? * [34.2] Where can I get a copy of "STL"? * [35.9] 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.31] What updates were made for the 11/94 release? New FAQs: * [3.1] Is there a C++ FAQ Book in addition to the C++ FAQ Lite? * [3.2] Is there a big difference between C++ FAQ Lite and C++ FAQ Book? * [4.31] What updates were made for the 11/94 release? ============================================================================== [4.32] 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.32] What updates were made for the 08/94 release? * [18.10] What do I do if I want a const member function to make an "invisible" change to a data member? * [29.3] Which is a better fit for C++: "static typing" or "dynamic typing"? ============================================================================== [4.33] 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 prior to 8/94. ============================================================================== User Contributions:Comment about this article, ask questions, or add new information about this topic: |
write my essay https://custompaperwritersservices.com cheap essay writer service https://essaywritingservicelinked.com