Expert C Programming

(Jeff_L) #1


template T min (T a, T b) { return (a < b)? a :


b; }


allows one to assign any arbitrary type T (for which the <


operator has been defined) to the variables a and b and the


function min. Some people refer to templates as providing


compiletime polymorphism. It's a bit of a stretch, but they mean


that a stated operation can be done on a variety of different


types, and it's all figured out at compiletime.



  • In-lining of functions: a programmer can stipulate that a particular function should be
    expanded in-line (as though it were a macro) in the instruction stream rather than generating a
    function call.

  • The operators new and delete, to replace malloc() and free() function calls. The
    operators are slightly more convenient (the sizeof calculation is done implicitly for
    example, and the proper constructor/destructor is called). new truly creates an object, whereas
    malloc just allocates memory.

  • Call-by-reference: C uses only call-by-value (except for arrays). C++ brings call-by-reference
    into the language.


Software Dogma


C++ Design Goals: That Was Then. This Is Now.


From SIGPLAN Notices, vol. 21, no. 10, October 1986 "An Overview of C++," by Bjarne
Stroustrup


Section 6. What is Missing?


C++ was designed under severe constraints of compatibility, internal consistency, and
efficiency: no feature was included that



  1. [1] would cause a serious incompatibility with C at the source or linker
    levels.

Free download pdf