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

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.20134 Мб27A.Menezes, P.van Oorschot,S.Vanstone - HANDBOOK OF APPLIED CRYPTOGRAPHY.djvu
  • #
  • #
    08.05.20136 Мб30B.Eckel - Thinking in Java, 3rd edition (beta).pdf
  • #
  • #
    08.05.20136 Мб23D.MacKay - Information Theory, Inference, and Learning Algorithms.djvu
  • #
    08.05.20134 Мб21DIGITAL Visual Fortran ver.5.0 - Programmers Guide to Fortran.djvu
  • #
    08.05.20132 Мб17E.A.Lee, P.Varaiya - Structure and Interpretation of Signals and Systems.djvu