Đang chuẩn bị liên kết để tải về tài liệu:
Lecture Programming in C++ - Chapter 17: Templates

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

On completion of this chapter students will know how to: Function templates; class templates; three types of sequences containers are vector, deque and list; basic components of STL are iterators, algorithms and containers; STL has both sequence and associative containers. | Chapter 17 – Templates Function Templates Express general form for a function Example: template for adding two numbers Lesson 17.1 template Type sum (Type a, Type b) { return (a + b); } Function Templates Called in same manner as ordinary function Permissible to have both generic data types and ordinary data types Treated similar to overloaded function Need to be careful that function call data types compatible with function bodies Useful for operations that apply to many data types Lesson 17.1 Overloaded Function Templates Cannot replace overloaded functions Perform same operations for each different data type Can vary number of arguments Specify more than one type of argument Distinguished by number or distribution of types of arguments Lesson 17.1 Class Templates: Example Lesson 17.2 template class Class1 { private: Type value; public: Class1 ( ); void set_value (Type); Type get_value ( ); }; Name of class Data member Constructor Member functions Class . | Chapter 17 – Templates Function Templates Express general form for a function Example: template for adding two numbers Lesson 17.1 template Type sum (Type a, Type b) { return (a + b); } Function Templates Called in same manner as ordinary function Permissible to have both generic data types and ordinary data types Treated similar to overloaded function Need to be careful that function call data types compatible with function bodies Useful for operations that apply to many data types Lesson 17.1 Overloaded Function Templates Cannot replace overloaded functions Perform same operations for each different data type Can vary number of arguments Specify more than one type of argument Distinguished by number or distribution of types of arguments Lesson 17.1 Class Templates: Example Lesson 17.2 template class Class1 { private: Type value; public: Class1 ( ); void set_value (Type); Type get_value ( ); }; Name of class Data member Constructor Member functions Class Template Allows creation of object of class and use the data type of choice Syntax to declare object Class1 ob; Indicates the ob.value is type double Lesson 17.2 Mechanics of Class Templates Declaration for object using class template Causes memory reserved for all data members Causes instructions to be generated and stored for all function members If another object with same bracketed data type declared New memory reserved, but no new function instructions Lesson 17.2 Friends of Class Templates Four cases (assuming single type parameter) Ordinary function friend of each template class instantiated from class template Ordinary class friend of each template class instantiated from class template Template function – only if type parameter for function and class same Template class – only matching type class is friend Lesson 17.2 Sequence Containers Designed to directly control position of element within container Three containers vector deque list Dynamic memory allocation used to .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.