As you might be aware, the C++ language is being updated by the ISO standard. The codename for the new C++ language is C++0x, and many compilers have already introduced few of the features. This tutorial is an attempt to give you introduction about the new changes in C++ language. Please note that, I am mainly explaining the new features for Visual C++ 2010 compiler only, although they are applicable for other compilers as well. I do not comment for absolute syntax in other compilers. This article assumes that you are having moderate knowledge of C++. You know what type casting is, what const methods are and what templates are (in basic sense).
New Features in C++Following it the list of new C++ language features, that I will be discussing. I've put more emphasis on lambdas. For now I've not used templates or STL for simplicity, but I would probably update this article to add content on templates/STL. * The auto keyword
* The decltype keyword
* The nullptr keyword
* The static_assert keyword
* Lambda expressions
* R-value referencesThe 'auto' keywordThe auto keyword now also has one more meaning. I assume you do know the original purpose of this keyword. With the revised meaning, you can declare a local variable without specifying the data-type of the variable. For example:
Collapseauto nVariable = 16;The code above declares nResult variable without specifying its type. With the expression on the right side the compiler deduces the type of variable. Thus the above code would be translated by compiler as:
Collapseint nVariable = 16;As you can also deduce, the assignment of variable is now mandatory. Thus, you cannot declare auto variable like:
Collapseauto nVariable ;
// Compiler error:
// error C3531: 'nVariable': a symbol whose type contains 'auto' must have an initializer Here the compiler does not (cannot) know the data type of variable nResult. Please note that, with auto keyword: * The datatype of a variable is determined at compile time, not at runtime.Having said that, no matter how complicated your assignment is, the compiler would still determine the datatype. If compiler cannot dedude the type, it would emit an error. This is not like Visual Basic or web scripting languages. Read more: Codeproject
New Features in C++Following it the list of new C++ language features, that I will be discussing. I've put more emphasis on lambdas. For now I've not used templates or STL for simplicity, but I would probably update this article to add content on templates/STL. * The auto keyword
* The decltype keyword
* The nullptr keyword
* The static_assert keyword
* Lambda expressions
* R-value referencesThe 'auto' keywordThe auto keyword now also has one more meaning. I assume you do know the original purpose of this keyword. With the revised meaning, you can declare a local variable without specifying the data-type of the variable. For example:
Collapseauto nVariable = 16;The code above declares nResult variable without specifying its type. With the expression on the right side the compiler deduces the type of variable. Thus the above code would be translated by compiler as:
Collapseint nVariable = 16;As you can also deduce, the assignment of variable is now mandatory. Thus, you cannot declare auto variable like:
Collapseauto nVariable ;
// Compiler error:
// error C3531: 'nVariable': a symbol whose type contains 'auto' must have an initializer Here the compiler does not (cannot) know the data type of variable nResult. Please note that, with auto keyword: * The datatype of a variable is determined at compile time, not at runtime.Having said that, no matter how complicated your assignment is, the compiler would still determine the datatype. If compiler cannot dedude the type, it would emit an error. This is not like Visual Basic or web scripting languages. Read more: Codeproject
0 comments:
Post a Comment