Expert C Programming

(Jeff_L) #1

  • Character literals have type char in C++, but type int in C. That is,
    sizeof('a') yields 1 in C++ and a larger value in C.

  • Pathological cases involving the // comment convention of C++ (as shown in
    Chapter 2).


There are many more differences, but you now know enough to be dangerous. So go out there and be
dangerous. When you're comfortable with the compiler and all the tools working in the ANSI C
subset, then spread your wings and start defining your own classes. Choose a good C++ book—look at
several, and choose one in a style you like. Make sure it is current with the language, which is still
evolving. Make sure it covers exceptions and templates, which were the latest two things added.


Just as with C, C++ standardization is now a joint effort of ISO (Working Group 21), and ANSI
X3J16. The most optimistic estimates predict that it will take around six years to standardize the
language, finishing in 1996, but make sure your C++ book mentions the ANSI C++ direction.


So What Is a Protected Abstract Virtual Base Pure Virtual Private
Destructor?

Let's break this down and take it a little bit at a time. The phrase actually decomposes into
two parts: a pure virtual private destructor that is inherited from a protected abstract
virtual base.


  • A private destructor is the function called when an object goes out of scope.
    "Private" means that it can only be called by a member or friend of the class.

  • A pure virtual function contains no code itself, but is used to act as a guide for
    other derived functions through inheritance.

  • A pure virtual destructor only makes sense if defined by a derived class. Since a
    destructor automatically does default clean-up actions on a class, like call member
    or base destructors, there is often no need to explicitly write any code in the
    destructor definition.


Simple enough. Tackling the second phrase


  • An abstract virtual base means that the base class is shared by the multiply-
    inherited classes (it's a "virtual base"), and that it contains at least one pure virtual
    function, from which other classes derive through inheritance (an "abstract base").
    Virtual base classes also have special initialization semantics.

  • A protected abstract virtual base class is one we inherited "protectedly," so our
    children know our parentage, but outsiders don't.


So, putting it all together, a protected abstract virtual base pure virtual private destructor
is a destructor function, that


  • can only be called by members or friends of the class, and

Free download pdf