home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / CPP_FAQ.TXT < prev    next >
Text File  |  1997-07-05  |  10KB  |  286 lines

  1. +++Date last modified: 05-Jul-1997
  2.  
  3. /* ==== CPP_ECHO.FAQ ========================== release 95-08-16 =========
  4.  
  5. This is the Frequently Asked Question list of the fidonet c_plusplus echo.
  6. Suggestions, enhancements, changes and comments will be appreciated.
  7.  
  8.  _____          Archivist/Editor: Auke Reitsma, Delft, The Netherlands.
  9.  /_|__|         Netmail         : 2:281/527
  10. /  | \  --------------------------------------------------------------- */
  11.  
  12. This CPP_echo FAQ list currently consists of four sections: "FAQ's", "New
  13. FAQ's", "Abbreviations and Terminology" and "Contributors". Each FAQ
  14. consists of a number, the question and a date on a single line -- if
  15. possible -- the answer, one or more lines listing the contributor and the
  16. (last) submission date and a 'last edit date'.
  17. The number uniquely identifies the question and will NEVER change. The
  18. question date should change when the question is asked again -- or used as
  19. answer -- in the cplusplus echo. In a relatively short time this will
  20. identify the unimportant questions, which will make it easier to delete
  21. these items.
  22. Three question marks indicate something that is at least somewhat doubtful
  23. and may need to be changed. Again, contributions are welcome.
  24. The "Abbreviations and Terminology" section is included to supply less
  25. common abbreviations and terms related to C++ and also to 'explain'
  26. abbreviations used in this list. It is also used for indexing and cross-
  27. referencing.
  28.  
  29. Auke Reitsma 95-07-15.
  30.  
  31. /* ---- Frequently Asked Questions ------------------------------------ */
  32.  
  33. 000     What is the topic of the C++ FAQ list?                  (95-04-15)
  34.  
  35. Any C++ related subject occurring 'frequently' in the cplusplus echo.
  36. There must be no doubts _at_all_ that it is on topic in the echo. This
  37. means that normal (ANSI) C subjects are not on topic for this list. Also
  38. the coverage of subjects specific to a platform, compiler or library will
  39. be limited.
  40.  
  41. 95-05-01
  42.  
  43.  
  44. 001     What is the difference between C and C++?               (95-04-15)
  45.  
  46. The essential difference is the "Object orientation" in C++.
  47.  
  48. 95-04-15
  49.  
  50.  
  51. 002     What normal C constructs work differently in C++?       (95-04-15)
  52.  
  53. - Assigning int's to enum's.
  54. - Assigning void pointers to other types of pointers.
  55. - Function declaration foo() without parameters.
  56. - Character constants are of type char in C++. They are of type int in C.
  57. - ALL functions MUST be prototyped in C++, which is not required in C.
  58. - In C++:
  59.         struct A { /* ... */ };
  60.   is equivalent to:
  61.         typedef struct A { /* ... */ } A;
  62.   in C.
  63.  
  64. See C++PL2, "Notes to the reader" (p. 11/12) and "C++ and ANSI-C" section
  65. r.18.2 (p.628/629) for more items and details.
  66.  
  67. Auke Reitsma [95-05-01], Jerry Coffin [95-05-06], David Nugent [95-04-16],
  68. Jari Laaksonen [95-04-15], 95-05-16
  69.  
  70.  
  71. 003     Why and when is a virtual destructor needed?            (95-04-15)
  72.  
  73. Any class that may act as the base of another class should have a virtual
  74. destructor. This ensures that when an object of the derived class is
  75. destroyed that the derived class dtor will be invoked to destroy it.
  76. If the destructor is not virtual, under some common circumstances, only
  77. the base class' destructor will be invoked, regardless of the class
  78. actually being destroyed.
  79. For practical purposes this means that a class which does, could or should
  80. have virtual member functions, should also have a virtual destructor.
  81.  
  82. Jerry Coffin [95-06-09], 95-06-16
  83.  
  84.  
  85. 004     How do I open binary files?                             (95-04-15)
  86.  
  87. Yeah, the various manuals and books are usually not clear that subject.
  88. With BC and MSC, you do a bitwise or of the file open mode with
  89. ios::binary, as in:
  90.  
  91.     ifstream mystream( "filename.ext", ios::in | ios::binary );
  92.  
  93. The default is ios::text for BC and MSC.
  94. However, this is NOT supported by Symantec 6.1. SC 6.1 doesn't have a flag
  95. to designate binary - it has ios::translated for text, and apparently to
  96. work with binary files you simply designate ios::in or ios::out without
  97. or'ing in ios::translated.
  98.  
  99. Jerry Coffin [95-05-06], 95-06-16
  100.  
  101.  
  102. 005     Why seem interrupt handlers as member functions to be impossible?
  103.                                                                 (95-04-15)
  104. Interrupt handlers as member functions _are_ possible. But they must be
  105. static member functions. Static member functions don't make use of the
  106. implicit 'this' pointer required by normal member functions. The caller of
  107. the interrupt handler doesn't know anything about objects and 'this'
  108. pointers, so it can't pass a value of such a pointer.
  109.  
  110. Auke Reitsma [95-04-15], 95-04-15
  111.  
  112.  
  113. 006     Is there a new/delete equivalent of realloc?            (95-05-01)
  114.  
  115. No. It would have a number of difficult problems. Some of these are:
  116. - Should the old instances in the memory be deleted and re-instantiated?
  117. - How about contained classes?
  118. - How about instances owned by the classes to be reallocated? These often
  119.   have a pointer to their owner.
  120.  
  121. Origin Unknown [??-??-??], 95-05-01
  122.  
  123.  
  124. 007     Floating point representation and output seems to be compiler
  125.         dependent.                                              (95-05-01)
  126.  
  127. Regrettably, yes. The action of ios::setprecision() varies among com-
  128. pilers.
  129.  
  130. David Nugent [95-04-16], 95-05-01
  131.  
  132.  
  133. 008     What is a "Copy Constructor"?                           (95-07-16)
  134.  
  135. A Copy Constructor constructs a new object as a copy of an existing object
  136. of the same type. Frequently copy constructors do a 'deep copy' of the
  137. object. X( const X& X_object ){...}; is a copy constructor for class X.
  138.  
  139. Deep Copy vs. Shallow Copy: a shallow copy simply copies the contents of
  140. an object directly - if the object contains pointers, both the old copy
  141. and the new copy contain pointers to the same actual item. In a deep copy,
  142. when an object contains a pointer, a new copy of whatever the pointer
  143. points AT is created and the new object contains a pointer to the newly
  144. created copy of the item.
  145. Why are deep copies important? If you carry out a shallow copy you end up
  146. with two pointers to the same item. If that item is an object with a
  147. destructor, this generally means you'll end up calling the destructor for
  148. that item twice, which will generally cause problems.
  149. Unfortunately, most don't know to ask this question directly: the symptom
  150. is generally heap corruption which is hard to track down directly since
  151. there it has many possible causes.
  152.  
  153. Jerry Coffin [95-07-04], 95-07-16
  154.  
  155.  
  156. 009     Why a "operator=(...)" when there is a copy ctor?       (95-07-16)
  157.  
  158. You use the assignment operator (operator = ()) whenever an existing
  159. object is to be replaced with a different object. The copy constructor
  160. X(const X&) is used to create a new instance of an X-object exactly like
  161. another.
  162.  
  163. Notice the subtle difference. Assignment changes an existing object while
  164. construction creates a new object. You can view assignment as the applica-
  165. tion of a destructor, to flush away the existing object, followed by a
  166. copy construction, to make an exact copy of the assigned object.
  167.  
  168. Cliff Rhodes [95-07-08], 95-07-16
  169.  
  170.  
  171. 010     What is an ABC: an "Abstract Base Class"?               (95-08-01)
  172.  
  173. An Abstract Base Class is a class that is not intended to be instantiated
  174. itself. Rather, it is intended strictly for use as a base for other
  175. classes. To prevent instantiation, an ABC will typically contain at least
  176. one pure virtual function.
  177.  
  178. The point of an ABC is to separate the interface of a group of classes
  179. from the implementation of the functions that make up the interface. This
  180. allows other code to ignore differences in how these functions are carried
  181. out. An ABC creates a contract between its descendants and any other code
  182. that uses them. The descendants must implement a certain set of functions.
  183. Code that uses them must use those functions to access whatever it is the
  184. object involved represents.
  185.  
  186. Jerry Coffin [95-07-14], 95-08-01
  187.  
  188.  
  189. 011     How is an ABC related to an "Abstract Data Type" (ADT)  (95-08-01)
  190.  
  191. An ADT is a concept - the basic idea of a data type that doesn't specify
  192. how the data type is implemented. An ABC is a method C++ provides for
  193. creating an ADT.
  194.  
  195. Jerry Coffin [95-07-26], 95-08-01
  196.  
  197.  
  198. 012     What is a 'pure' virtual function and what's its use?   (95-08-01)
  199.  
  200. A pure virtual function is signified by using `=0;' in place of the body
  201. of the function. The presence of a pure virtual function prevents
  202. instantiation of the class which contains it. For this to be of any use, a
  203. derived class must implement the pure virtual function. I.e. the derived
  204. class must provide a function with the same name which includes a function
  205. body.
  206. The basic reason for pure virtual functions is to specify something that
  207. a class can do without specifying how the class will do it.
  208.  
  209. Jerry Coffin [95-07-26], 95-08-01
  210.  
  211.  
  212. /* ---- New since previous release -- provisionally numbered ---------- */
  213.  
  214. None.
  215.  
  216.  
  217. /* ---- Abbreviations and Terminology --------------------------------- */
  218.  
  219. This section also serves as an index.
  220.  
  221. ABC     Abstract Base Class, see FAQ #010 and #011
  222.  
  223. ADT     Abstract Data Type, see FAQ #011
  224.  
  225. ARM     "The Annotated C++ Reference Manual"
  226.         by B. Stroustrup and M.A. Ellis. ISBN 0-201-51459-1
  227.  
  228. assignment operator
  229.         See FAQ #009
  230.  
  231. BC      Borland C. Usually including the Turbo products.
  232.  
  233. binary files
  234.         See FAQ #004
  235.  
  236. C++PL2  "The C++ Programming Language" second edition
  237.         by B. Stroustrup, ISBN 0-201-53992-6
  238.  
  239. copy constructor
  240.         See FAQ #008
  241.  
  242. ctor    constructor
  243.  
  244. deep copy
  245.         See FAQ #008
  246.  
  247. dtor    destructor
  248.  
  249. interrupt handlers
  250.         See FAQ #005
  251.  
  252. MSC     Microsoft C.
  253.  
  254. pure virtual function
  255.         See FAQ #012
  256.  
  257. SC      Symantec C.
  258.  
  259. shallow copy
  260.         See FAQ #008
  261.  
  262. static member functions
  263.         See FAQ #005
  264.  
  265. subclass
  266.         Not a correct C++ term at all. Use "derived class". See ARM p.197
  267.  
  268. superclass
  269.         Not a correct C++ term at all. Use "base class". See ARM p.197
  270.  
  271. virtual destructor
  272.         See FAQ #003
  273.  
  274. virtual function, pure
  275.         See FAQ #012
  276.  
  277. /* ---- Contributors -------------------------------------------------- */
  278.  
  279. Jerry Coffin
  280. Jari Laaksonen
  281. David Nugent
  282. Auke Reitsma
  283. Cliff Rhodes
  284.  
  285. /* ==== CPP_ECHO.FAQ end ============================================== */
  286.