O'Reilly logo

Mastering C++ Programming by Jeganathan Swaminathan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

New rules for type auto-detection from braced initializer list 

C++17 introduced new rules for auto-detection of the initializer list, which complements C++14 rules. The C++17 rule insists that the program is ill-formed if an explicit or partial specialization of std::initializer_list is declared:

#include <iostream>using namespace std;template <typename T1, typename T2>class MyClass {     private:          T1 t1;          T2 t2;     public:          MyClass( T1 t1 = T1(), T2 t2 = T2() ) { }          void printSizeOfDataTypes() {               cout << "\nSize of t1 is " << sizeof ( t1 ) << " bytes." << endl;               cout << "\nSize of t2 is " << sizeof ( t2 ) << " bytes." << endl;     }};int main ( ) {    //Until C++14    MyClass<int, double> obj1;    obj1.printSizeOfDataTypes( );    //New syntax in C++17 MyClass obj2( ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required