home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C22 / Overhead.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  905 b   |  43 lines

  1. //: C22:Overhead.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Virtual base class overhead
  7. #include <fstream>
  8. using namespace std;
  9. ofstream out("overhead.out");
  10.  
  11. class MBase {
  12. public:
  13.   virtual void f() const {};
  14.   virtual ~MBase() {}
  15. };
  16.  
  17. class NonVirtualInheritance
  18.   : public MBase {};
  19.  
  20. class VirtualInheritance
  21.   : virtual public MBase {};
  22.  
  23. class VirtualInheritance2
  24.   : virtual public MBase {};
  25.  
  26. class MI
  27.   : public VirtualInheritance,
  28.     public VirtualInheritance2 {};
  29.  
  30. #define WRITE(ARG) \
  31. out << #ARG << " = " << ARG << endl;
  32.  
  33. int main() {
  34.   MBase b;
  35.   WRITE(sizeof(b));
  36.   NonVirtualInheritance nonv_inheritance;
  37.   WRITE(sizeof(nonv_inheritance));
  38.   VirtualInheritance v_inheritance;
  39.   WRITE(sizeof(v_inheritance));
  40.   MI mi;
  41.   WRITE(sizeof(mi));
  42. } ///:~
  43.