ility> #i nclude #inc

Автор admin Воскресенье, 14 июня 2009 11:32

ility> #i nclude #include “Trash.h” #include “../purge.h” using namespace std: // Критерий сравнения указателей на type_info struct TInfoLess { bool operatorO(const type_info* tl. const type_info* t2) const { return tl->before(*t2); } }: typedef map. TInfoLess> TrashMap; // Вычисление суммарной стоимости одного вида мусора: void sumValue(const TrashMap::value_type& p. ostream& os) { vector::const_iterator tally = p.second.begin(); float val =0; while(tally != p.second.endO) { val += (*tally)->weight() * (*tally)->value(); os « “weight of ” « p.first->name() // type_info::name() « ” = ” « (*ta1ly)->weight() « endl: ++tally; } os « “Total value = ” « val « endl; } int mainO { srand(time(0)); // Раскрутка генератора случайных чисел TrashMap bin: Реализация и издержки RTTI 439 // Заполнение контейнера объектами Trash: fordnt i = 0: i < 30: i++) { Trash* tp; switch(rand() % 3) { case 0 : tp – new Aluminum((rand() % 1000)/10.0): break: case 1 : tp – new Paper((rand() % 1000)/10.0): break; case 2 : tp = new Glass((rand() % 1000)/10.0): break: } bi n[&typei d


Комментарии закрыты.