Summary

 < Day Day Up > 



Static polymorphism happens at compile time. Function templates are generic function definitions used by the compiler to construct specific function versions based on the types of arguments used to call the function. Function template declaration and definition should appear in the same header file unless your compiler supports separating the declaration of a function template from its definition.

Function templates are declared using the template keyword. Type placeholders are declared using the class keyword and can be any valid identifier. There can be more than one type placeholder declared and used in a function template. Because the compiler uses the function template to build a specific version of the function, using more than one type in a function call to a function having only one type placeholder can be problematic.

Use the template specialization syntax to specify placeholder types when the function template is called.

Class templates provide a way to write generic classes to gain an additional measure of code reuse. Class template declarations are started with the template keyword followed by the template parameter list. Class templates can have more than one template parameter just like their function template cousins. Group class template declaration and definition in a common header file unless your compiler supports their separation.

The C++ standard template library (STL) provides containers, iterators, and algorithms for use in your programs. Containers are components that manage a set of elements. Container adapters rely on containers to implement their functionality. The type of container used by a container adapter is left to the choice of the programmer.

Iterators provide a mechanism to manipulate the elements managed by a container. Algorithms make extensive use of iterators to provide you with additional alternatives to manipulate container elements.

Container, iterators, and algorithms all work together to add ready-made functionality to your programs. Getting to know the STL can save you a lot of otherwise wasted effort expended in trying to replicate what is already available.



 < Day Day Up > 



C++ for Artists. The Art, Philosophy, and Science of Object-Oriented Programming
C++ For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504028
EAN: 2147483647
Year: 2003
Pages: 340
Authors: Rick Miller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net