Sunday, January 8, 2017

C++11 Features (Part 1)


Here i'm listing some of the C++ 11 features we can use frequently.

1.Auto
2.Range Based for loop
3.Strongly typed enums
4.Forward enum declaration

To use C++ 11 features when compiling in commad line use any of the following flags

  $g++ -o myprog myprog.cpp -std=c++0x  (or)  
  $g++ -o myprog myprog.cpp -std=gnu++0x (or)  
  $g++ -o myprog myprog.cpp -std=c++11    

Auto:
Before C++11 auto keyword is used in the storage class, from C++11 it is used as type inference, means automatic deduction of data type of an expression.
We can use auto inside the blocks, namespaces, and for loop initialization etc. Using auto we can reduce writing the some complex type declarations like iterators intialization in loop.