[计算机科学经

6 container types templates c templates polymorphic

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: generation " << generation << " (total: " << n_created - n_destroyed << ')' << std::endl; } // 解構式(destructor) ~SortTracer() { ++n_destroyed; update_max_live(); std::cerr << "SortTracer generation " << generation << " destroyed (total: " << n_created - n_destroyed << ')' << std::endl; } // 賦值(assignment) SortTracer& operator= (SortTracer const& b) { ++n_assigned; std::cerr << "SortTracer assignment #" << n_assigned << " (generation " << generation << " = " << b.generation << ')' << std::endl; value = b.value; return *this; } // 比較(comparison) friend bool operator < (SortTracer const& a, SortTracer const& b) { ++n_compared; C++ Templates - The Complete Guide 6 82 實際運用 Templates std::cerr << "SortTracer comparison #" << n_compared << " (generation " << a.generation << " < " << b.generation << ')' << std::endl; return a.value < b.value; } int val() const { return value; } }; 除了 追蹤待排序 值 value 外 ,這個追 蹤器還提供若干 成員 ,用來追蹤 實際排序 的過程 : generation 追蹤...
View Full Document

Ask a homework question - tutors are online