Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
B.Eckel - Thinking in C++, Vol.2, 2nd edition.pdf
Скачиваний:
59
Добавлен:
08.05.2013
Размер:
2.09 Mб
Скачать

b.push_back(new X);

for(int i = 0; i < b.size(); i++) cout << b[i]->vf() << endl;

purge(b); } ///:~

If you can always arrange for a virtual base class to have a default constructor, you’ll make things much easier for anyone who inherits from that class.

Overhead

The term “pointer magic” has been used to describe the way virtual inheritance is implemented. You can see the physical overhead of virtual inheritance with the following program:

//: C06:Overhead.cpp

// Virtual base class overhead #include <fstream>

using namespace std;

ofstream out("overhead.out");

class MBase { public:

virtual void f() const {}; virtual ~MBase() {}

};

class NonVirtualInheritance : public MBase {};

class VirtualInheritance

: virtual public MBase {};

class VirtualInheritance2

: virtual public MBase {};

class MI

:public VirtualInheritance, public VirtualInheritance2 {};

#define WRITE(ARG) \

out << #ARG << " = " << ARG << endl;

Chapter 15: Multiple Inheritance

351

Соседние файлы в предмете Численные методы
  • #
    08.05.20133.99 Mб25A.Menezes, P.van Oorschot,S.Vanstone - HANDBOOK OF APPLIED CRYPTOGRAPHY.djvu
  • #
  • #
    08.05.20135.91 Mб28B.Eckel - Thinking in Java, 3rd edition (beta).pdf
  • #
  • #
    08.05.20136.09 Mб20D.MacKay - Information Theory, Inference, and Learning Algorithms.djvu
  • #
    08.05.20133.85 Mб19DIGITAL Visual Fortran ver.5.0 - Programmers Guide to Fortran.djvu
  • #
    08.05.20131.84 Mб16E.A.Lee, P.Varaiya - Structure and Interpretation of Signals and Systems.djvu