Professional Documents
Culture Documents
Overview
Understanding C++
Templates his article is a follow-up to the
In this article, we’ll learn the basic syntax and
T
‘An Introduction to C++
semantics of the features in the templates in C++ and Templates’ article published in
the October issue of LFY. So,
write small programs.
without further ado, let’s get
started.
Template instantiation
We can ‘use’ the template by providing
necessary arguments, which is known as
instantiating the template. An instance
created from that template is a template
instantiation. For class templates, we have to
explicitly provide the instantiation arguments.
For function templates, we can explicitly
provide the template arguments or else the
CMYK
Overview
CMYK
Overview
// explicit specialization for swapping my_vector’s By: S.G. Ganesh is a research engineer in Siemens
template <> (Corporate Technology). He has authored a book “Deep C”
void swap(my_vector &t1, my_vector &t2) { (ISBN 81-7656-501-6). You can reach him at
// call my_vector::swap for swapping two my_vector’s sgganesh@gmail.com.
CMYK