Declarations
C++11 implements several features that simplify declarations, particularly for situations arising when templates are used.
auto
C++11 strips the keyword auto of its former meaning as a storage class specifier (Chapter 9, “Memory Models and Namespaces”) and puts it to use (Chapter 3) to implement automatic type deduction, provided that an explicit initializer is given. The compiler sets the type of the variable to the type of the initialization value:
auto maton = 112; // maton is type intauto pt = &maton; // pt is type int *double fm(double, int);auto pf = fm; // pf is type double (*)(double,int)
The auto keyword can simplify template declarations too. For example, if il is an object of type std::initializer_list<double>
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.
Read now
Unlock full access