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

os << "--------" << endl; return os;

}

void Bicycle::print(vector<Bicycle*>& vb, ostream& os) {

copy(vb.begin(), vb.end(), ostream_iterator<Bicycle*>(os, "\n"));

cout << "--------" << endl; } ///:~

Here’s a test:

//: C09:BikeTest.cpp //{L} Bicycle #include "Bicycle.h" #include <algorithm> using namespace std;

int main() { vector<Bicycle*> bikes; BicycleGenerator bg;

generate_n(back_inserter(bikes), 12, bg); Bicycle::print(bikes);

} ///:~

Exercises

1.Create a heap compactor for all dynamic memory in a particular program. This will require that you control how objects are dynamically created and used (do you overload operator new or does that approach work?). The typically heap-compaction scheme requires that all pointers are doublyindirected (that is, pointers to pointers) so the “middle tier” pointer can be manipulated during compaction. Consider overloading operator-> to accomplish this, since that operator has special behavior which will probably benefit your heap-compaction scheme. Write a program to test your heap-compaction scheme.

Chapter 16: Design Patterns

428

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