Kinh doanh - Marketing
Kinh tế quản lý
Biểu mẫu - Văn bản
Tài chính - Ngân hàng
Công nghệ thông tin
Tiếng anh ngoại ngữ
Kĩ thuật công nghệ
Khoa học tự nhiên
Khoa học xã hội
Văn hóa nghệ thuật
Sức khỏe - Y tế
Văn bản luật
Nông Lâm Ngư
Kỹ năng mềm
Luận văn - Báo cáo
Giải trí - Thư giãn
Tài liệu phổ thông
Văn mẫu
Giới thiệu
Đăng ký
Đăng nhập
Tìm
Danh mục
Kinh doanh - Marketing
Kinh tế quản lý
Biểu mẫu - Văn bản
Tài chính - Ngân hàng
Công nghệ thông tin
Tiếng anh ngoại ngữ
Kĩ thuật công nghệ
Khoa học tự nhiên
Khoa học xã hội
Văn hóa nghệ thuật
Y tế sức khỏe
Văn bản luật
Nông lâm ngư
Kĩ năng mềm
Luận văn - Báo cáo
Giải trí - Thư giãn
Tài liệu phổ thông
Văn mẫu
Thông tin
Điều khoản sử dụng
Quy định bảo mật
Quy chế hoạt động
Chính sách bản quyền
Giới thiệu
Đăng ký
Đăng nhập
0
Trang chủ
Công Nghệ Thông Tin
Kỹ thuật lập trình
Lecture Data structures and other objects using C++ - Chapter 6: Template functions
Đang chuẩn bị liên kết để tải về tài liệu:
Lecture Data structures and other objects using C++ - Chapter 6: Template functions
Thanh Tùng
79
13
ppt
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Templates are an important part of C++ that allows a programmer to reuse existing code for new purposes. In some sense, templates ensure that you don’t have to continually “reinvent the wheel.” This lecture introduces how to implement and use template functions. The best time for the lecture is just before the students read chapter 6. | Chapter 6 introduces templates, which are a C++ feature that easily permits the reuse of existing code for new purposes. This presentation shows how to implement and use the simplest kinds of templates: template functions. Template Functions CHAPTER 6 Data Structures and Other Objects Templates are an important part of C++ that allows a programmer to reuse existing code for new purposes. In some sense, templates ensure that you don’t have to continually “reinvent the wheel.” This lecture introduces how to implement and use template functions. The best time for the lecture is just before the students read Chapter 6. Here’s a small function that you might write to find the maximum of two integers. int maximum(int a, int b) { if (a > b) return a; else return b; } Finding the Maximum of Two Integers To illustrate template functions, let’s look at this simple function. It would appear as part of a program that needs to find the larger of two integers. The function returns a copy of the larger of its two arguments. Here’s a small function that you might write to find the maximum of two double numbers. int maximum(double a, double b) { if (a > b) return a; else return b; } Finding the Maximum of Two Doubles Suppose your program also needs to find the larger of two double numbers. Then you could add a second function for double numbers. By the way, you may use the same name, maximum, for the two functions. The compiler is smart enough to determine which function your program is using at any given point, by looking at the types of the parameters. Here’s a small function that you might write to find the maximum of two knafns. int maximum(knafn a, knafn b) { if (a > b) return a; else return b; } Finding the Maximum of Two Knafns Suppose your program also has another data type, called knafn. This could be a class that you wrote yourself for some purpose. Anyway, perhaps knafn objects can be compared with the > operation (because the knafn implementation includes an overloaded | Chapter 6 introduces templates, which are a C++ feature that easily permits the reuse of existing code for new purposes. This presentation shows how to implement and use the simplest kinds of templates: template functions. Template Functions CHAPTER 6 Data Structures and Other Objects Templates are an important part of C++ that allows a programmer to reuse existing code for new purposes. In some sense, templates ensure that you don’t have to continually “reinvent the wheel.” This lecture introduces how to implement and use template functions. The best time for the lecture is just before the students read Chapter 6. Here’s a small function that you might write to find the maximum of two integers. int maximum(int a, int b) { if (a > b) return a; else return b; } Finding the Maximum of Two Integers To illustrate template functions, let’s look at this simple function. It would appear as part of a program that needs to find the larger of two integers. The function returns a copy of the .
TÀI LIỆU LIÊN QUAN
Lecture Data structures and other objects using C++ - Chapter 7: Using a stack
Lecture Data structures and other objects using C++ - Chapter 8: Using a queue
Lecture Data structures and other objects using C++ - Chapter 7: Using a stack
Lecture Data structures and other objects using C++ - Chapter 8: Using a queue
Lecture Data structures and other objects using C++ - Chapter 10b: Binary search trees
Lecture Data structures and other objects using C++ - Chapter 10b: Binary search trees
Lecture Data structures and other objects using C++ - Chapter 6: Template functions
Lecture Data structures and other objects using C++ - Chapter 6: Template functions
Lecture Data structures and other objects using C++ - Chapter 1: Preconditions and postconditions
Lecture Data structures and other objects using C++ - Chapter 2: Object-oriented programming
crossorigin="anonymous">
Đã 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.