What are the new changes introduced in C++11?

C++11 is a version of standard C++ language. It was approved by International Organization for Standardization (ISO) on 12 August 2011 then C++14 and C++17. C++11 makes several additions to the core language.

There are some of the new changes introduced in C++11 −

  • nullptr − In the previous nullptr, zero used to be the value and it had a drawback of implicit conversion to integral value. The null pointer literal is represented by std::nullptr_t. In this nullptr, no implicit conversion exists.

  • Lambdas − The lambda expression allows to define functions locally. Anonymous functions are known as lambda. We can use lambda expression wherever the function object std::function is expected.

  • Smart pointers − The smart pointer auto_ptr was the only smart pointer and now it is deprecated. There are three other smart pointers are added in C++11 i.e. shared_ptr, unique_ptr and weak_ptr.

  • auto − In previous versions, we must specify the type of the object but in C++11, there is no need to specify the type which means you can declare the variables directly without specifying their type.

  • Override and Final − The version C++11 has introduced two new special identifiers i.e. override and final. Override indicates that the method is supposed to be override of virtual method in base class. On the other hand, final indicates that derived class should not override the virtual method.

  • Deleted and defaulted functions − The deleted functions are useful for preventing object copying. To disable copying, “ =delete; “ is used. The default function gives instruction to the compiler to generate default implementation of function and “ =default; “ is used for default functions.

  • Range-based for loops − C++11 introduced range-based for loops for iterating over collections. Now, it is possible to iterate over like C-arrays. It supports ‘foreach’ paradigm of iterating over.

  • Strongly-typed enums − In the traditional enums, They used to export their enumerators in surrounding scope. They are specified as “enum class” keyword. They do not export their enumerators in surrounding scope.

  • Static_assert and type traits − It performs an assertion check at the time of compilation. If the assertion is true, it displays nothing otherwise it displays an error message.

  • New C++ algorithms − The C++11 standard library introduced new algorithms with some operations like all_of(), any_of and none_of().

Updated on: 30-Jul-2019


Kickstart Your Career

Get certified by completing the course

Get Started