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...

Each time the compiler sees the use of a template class with a given type, it creates a version of that type implicitly. This, however, can happen multiple times, reducing the speed of the compiler. If, however, the types that are expected to be used are known upfront, this issue can be solved using explicit template specialization. Take a look at this example:

#include <iostream>template<typename T>class the_answer{public:    the_answer(T t)    {        std::cout << "The answer is: " << t << '\n';    }};

Earlier, we created a simple structure that outputs to stdout during construction. Normally, this class would be created by the compiler once the first specialization of the class is seen. We can, however, perform the following:

template ...
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