TAILIEUCHUNG - Lecture Programming in C++ - Chapter 17: Templates

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 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 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 Class Templates: Example Lesson template class Class1 { private: Type value; public: Class1 ( ); void set_value (Type); Type get_value ( ); }; Name of class Data member Constructor Member functions Class .

TỪ KHÓA LIÊN QUAN
Đã 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.