Lập trình hướng đối tượng - Chương 6 potx

117 335 0
Lập trình hướng đối tượng - Chương 6 potx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Lập trình hướng đối tượng - STL 1 Chương 6 Standard Template Library Lập trình hướng đối tượng - STL 2 The Standard Template Library • Origins of STL • Generic programming • STL components • STL installation • STL header files • STL incompatibilities Lập trình hướng đối tượng - STL 3 The Standard Template Library • Standard Template Library (STL)    •  !! ""  Lập trình hướng đối tượng - STL 4 Problems with libraries • #    $  • % &' – ( – () – * Lập trình hướng đối tượng - STL 5 Origins of STL • ( +,( !!   • +-. /0&  1223  !! Lập trình hướng đối tượng - STL 6 #4 • +,( ' – 5) – ( – 6 – 78 – + Lập trình hướng đối tượng - STL 7 6 • 9     Lập trình hướng đối tượng - STL 8 6 • 5:    •  :  : Lập trình hướng đối tượng - STL 9 6 • ,    )   Lập trình hướng đối tượng - STL 10  •  • 6 • ( • + • 78 • + [...]... sort(&x[0], &x[100]); // Sort using the function object comp as the // comparison operation sort(&x[0], &x[100],comp); 28 Allocators • Allocators store information about particular memory models e.g 1 6- bit, 32-bit • An STL container can be made to work with a particular memory model simply by passing it a suitable allocator as a template parameter template class vector;... your file: #define MINMAX_DEFINED #pragma option -vi- 33 Conventions used in examples • All of the examples in these lectures are compatible with the ANSI C++ standard • If you want to compile the examples with the HP reference implementation of STL running on either Borland C++ 4.5 or Turbo C++ 4.5 : • Add #define MINMAX_DEFINED and #pragma option -vidirectives; • remove the using namespace std declaration;... associated with data They also allow functions to be created, stored, and destroyed just like any other kind of object • Many STL containers and algorithms use function objects to perform their duties 26 • A function object encapsulates a function in an object for use by other components • In C++ programming, we define a function object to be an instance of any class that overloads the function call... Queensland"; int length = strlen(string1); // Reverse the array std::reverse(&string1[0], &string1[length]); // Check that the reversal was successful assert(strcmp(string1, "dnalsneeuQ lartneC") == 0); } 16 #include #include #include using namespace::std; // Return aVector containing the characters of aString // (not including the terminating null character) vector getVector(char*... Reverse the vector reverse(vector1.begin(), vector1.end()); // Check that the reversal was successful assert(vector1 == getVector("dnalsneeuQ lartneC")); return 0; } 18 Iterators • Iterators are pointer-like objects that can be used to visit the individual elements of a container • STL algorithms are written in terms of iterator parameters, and STL containers provide the iterators that can be plugged... -vidirectives; • remove the using namespace std declaration; and • make minor adjustments to the #include directives 34 The following code works with Borland C++ 4.5 #define MINMAX_DEFINED #pragma option -vi#include #include #include #include // Return aVector containing the characters of aString // (not including the terminating null character) vector... vector::iterator i; // Reverse the vector reverse(vector1.begin(), vector1.end()); // Display the contents of the vector for (i = vector1.begin(); i != vector1.end(); i++) cout . Lập trình hướng đối tượng - STL 1 Chương 6 Standard Template Library Lập trình hướng đối tượng - STL 2 The Standard Template Library • Origins. STL 9 6  • ,    )   Lập trình hướng đối tượng - STL 10  •  • 6  • ( • + • 78 • + Lập trình hướng đối tượng - STL 11 . STL 6 #4 • +,( ' – 5) – ( – 6  – 78 – + Lập trình hướng đối tượng - STL 7 6  • 9     Lập trình hướng

Ngày đăng: 09/07/2014, 00:20

Từ khóa liên quan

Mục lục

  • Slide 1

  • The Standard Template Library

  • The Standard Template Library

  • Problems with libraries

  • Origins of STL

  • Why STL?

  • Generic programming

  • Slide 8

  • Generic programming

  • STL components

  • Containers

  • Sequential containers

  • Associative containers

  • Generic algorithms (I)

  • Generic algorithms (II)

  • Slide 16

  • Slide 17

  • Slide 18

  • Iterators

  • Slide 20

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan