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

Class template type deduction is a new feature added in C++17 that provides the ability to deduce the type of a template class from its constructor. Suppose we have the following class template:

template<typename T>class the_answer{public:    the_answer(T t)    {        show_type(t);    }};

As shown in the preceding code snippet, we have a simple class template that takes a type T during construction and uses a show_type() function to output whatever type it is given. Before C++17, this class would have been instantiated using the following:

int main(void){    the_answer<int> is(42);}

With C++17, we can now instantiate this class as follows:

int main(void){    the_answer is(42);}

The reason this works is that the constructor of the class takes ...

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