Skip to Content
Advanced C++ Programming Cookbook
book

Advanced C++ Programming Cookbook

by Dr. Rian Quinn
January 2020
Intermediate to advanced
454 pages
11h 25m
English
Packt Publishing
Content preview from Advanced C++ Programming Cookbook

How it works...

One of the oldest and most widely used features of C++ is C++ templates. Like inheritance, C++ templates are not generally described as a form of type erasure, but they are. Type erasure is nothing more than the act of removing or, in this case, ignoring type information.

Unlike the C language, however, type erasure in C++ generally attempts to avoid removing type information in favor of working around a type's strict definition while retaining type safety. One way to accomplish this is through the use of C++ templates. To better explain this, let's start with a simple example of a C++ template:

template<typename T>T pow2(T t){    return t * t;}

In the preceding example, we have created a simple function that calculates the power ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Modern C++ Programming Cookbook

Modern C++ Programming Cookbook

Marius Bancila

Publisher Resources

ISBN: 9781838559915Supplemental Content