
C/C++ Programming Techniques
ET2031/ ET2031E

Lecturer: PhD. DO Thi Ngoc Diep
SCHOOL OF ELECTRICAL AND ELECTRONIC ENGINEERING
HANOI UNIVERSITY OF SCIENCE AND TECHNOLOGY
Chapter 7: Standard
Template Library

3
Content
•7.1. Template
•Concept
•Function template
•Class template
•7.2. Standard Template Library
•Introduction
•String
•Containers:
•Algorithm

4
7.1. Template

Introduction
•Program needs to work with several data types, including data
types in the future
•Function overloading
int max_(int a, int b) { return a>b ? a:b; }
double max_(double a, double b) { return a>b ? a:b; }
float max_(float a, float b) { return a>b ? a:b; }
•Void pointer
•In C: memcpy() in string.h
void* memcpy(void* region1, const void* region2, size_t n);
max_(a, b)
•int
•String
•Complex object
•...
The same algorithm, only
different in data type

