3
Understanding and Designing Templates
Templates are a unique feature of C++ by which functions and classes have the ability to support generic data types—in other words, we can implement a function or class independent of a particular data type; for example, a client may request a max() function to handle different data types. Instead of implementing and maintaining many similar functions by using function overloading, we can just implement one max() function and pass the data type as a parameter. Moreover, templates can work together with multiple inheritance and operator overloading to create powerful generic data structures and algorithms in C++ such as the Standard Template Library (STL). Additionally, templates can also be applied to ...
Get Expert C++ - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.